Skip to content

Commit 710c156

Browse files
authored
fix(chromium): disable same site by default and improved controls (#2097)
1 parent 142e585 commit 710c156

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

src/chromium/crBrowser.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,6 @@ export class CRBrowserContext extends BrowserContextBase {
343343
}
344344

345345
async addCookies(cookies: network.SetNetworkCookieParam[]) {
346-
cookies = cookies.map(c => {
347-
const copy = { ...c };
348-
// Working around setter issue in Chrome. Cookies are now None by default.
349-
if (copy.sameSite === 'None')
350-
delete copy.sameSite;
351-
return copy;
352-
});
353346
await this._browser._session.send('Storage.setCookies', { cookies: network.rewriteCookies(cookies), browserContextId: this._browserContextId || undefined });
354347
}
355348

src/server/chromium.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ const DEFAULT_ARGS = [
304304
'--disable-dev-shm-usage',
305305
'--disable-extensions',
306306
// BlinkGenPropertyTrees disabled due to crbug.com/937609
307-
'--disable-features=TranslateUI,BlinkGenPropertyTrees',
307+
'--disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies',
308308
'--disable-hang-monitor',
309309
'--disable-ipc-flooding-protection',
310310
'--disable-popup-blocking',

test/headful.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,39 @@ describe('Headful', function() {
7979
await page.click('button');
8080
await browser.close();
8181
});
82+
it('should(not) block third party cookies', async({browserType, defaultBrowserOptions, server}) => {
83+
const browser = await browserType.launch({...defaultBrowserOptions, headless: false });
84+
const page = await browser.newPage();
85+
await page.goto(server.EMPTY_PAGE);
86+
await page.evaluate(src => {
87+
let fulfill;
88+
const promise = new Promise(x => fulfill = x);
89+
const iframe = document.createElement('iframe');
90+
document.body.appendChild(iframe);
91+
iframe.onload = fulfill;
92+
iframe.src = src;
93+
return promise;
94+
}, server.CROSS_PROCESS_PREFIX + '/grid.html');
95+
await page.frames()[1].evaluate(`document.cookie = 'username=John Doe'`);
96+
await page.waitForTimeout(2000);
97+
const allowsThirdParty = CHROMIUM || FFOX;
98+
const cookies = await page.context().cookies(server.CROSS_PROCESS_PREFIX + '/grid.html');
99+
if (allowsThirdParty) {
100+
expect(cookies).toEqual([
101+
{
102+
"domain": "127.0.0.1",
103+
"expires": -1,
104+
"httpOnly": false,
105+
"name": "username",
106+
"path": "/",
107+
"sameSite": "None",
108+
"secure": false,
109+
"value": "John Doe"
110+
}
111+
]);
112+
} else {
113+
expect(cookies).toEqual([]);
114+
}
115+
await browser.close();
116+
});
82117
});

0 commit comments

Comments
 (0)