Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/human-machine-swapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@

for (const path of PROBE_PATHS) {
try {
const response = await fetch(path, { method: "HEAD", credentials: "omit" });
// same-origin, not omit: behind a login (a Vercel preview, an intranet) a cookieless
// request is bounced to the login page, the probe fails, and the pill never appears.
// Cookies still never go to another origin.
const response = await fetch(path, { method: "HEAD", credentials: "same-origin" });
if (response.ok) {
try {
window.sessionStorage.setItem(cacheKey, path);
Expand Down Expand Up @@ -472,7 +475,9 @@

if (!this._text) {
try {
const response = await fetch(href, { credentials: "omit" });
// same-origin: see the probe above. With "omit", a protected deployment bounced this
// to its login page, the fetch failed, and the reader fell back to the raw file.
const response = await fetch(href, { credentials: "same-origin" });
if (!response.ok) throw new Error(String(response.status));
this._text = await response.text();
} catch (error) {
Expand Down
8 changes: 8 additions & 0 deletions test/component.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,11 @@ test("package.json points at the manifest and ships it", () => {
assert.equal(PKG.customElements, "custom-elements.json");
assert.ok(PKG.files.includes("custom-elements.json"));
});

test("it sends cookies to its own origin, so the reader works behind a login", () => {
// With credentials: "omit", a password-protected deployment (e.g. a Vercel preview) sent the
// fetch to its login page, the reader failed, and Machine fell back to the raw file.
assert.ok(!/credentials:\s*"omit"/.test(SOURCE), "no fetch may drop same-origin cookies");
assert.equal((SOURCE.match(/credentials:\s*"same-origin"/g) || []).length, 2);
});

Loading