Issue 1:
It would be great if we could load a chrome extension only once and reuse the same persistent context across multiple tests. Right now, if I load the chrome extension in global-setup.js, I am unable to get the chromium instance that contains the extension. I need to test communication between a dApp and a browser extension, so the dApp and the extension should share the same browser instance.

Currently, if follow the docs, each time I run a new test, a new chromium instance launches with the persistent context.

I'm trying to test a relatively heavy chrome extension, so I would prefer to load the chrome extension globally and then re-use the context in each of my subsequent tests.

As a hacky work around, I tried to defer a promise like so

// global-setup.js
import { chromium } from '@playwright/test'
import testConfig from './config'

let context

let contextIsResolved
const contextIsLoaded = new Promise(
(resolve) => (contextIsResolved = resolve)
)

export default async (config) => {
const pathToExtension = testConfig.browserExtensionPath
context = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
],
})
contextIsResolved(context)
await context.waitForEvent('page')
// extension is after the blank ghost page
// see issue https://github.com/microsoft/playwright-python/issues/689
const extensionPage = context.pages()[1]
}

export const getGlobalContext = async () => {
await contextIsLoaded
return context
}

// some-test.spec.js
import { getGlobalContext } from '../global-setup'

test.beforeAll(async ({ context }) => {
const context = await getGlobalContext() // this just hangs forever
})

The issue with the above (which I thought might work) is that the promise never resolves and it hangs indefinitely. Thus, the test suite fails.

I tried all tests in a single file like below

// main.spec.js
import { test, expect } from '../fixtures/browser-extension'
import { createPageModelObject } from '../page-object-models/base-page-object-model';

let extensionPage // reference for all the tests

test.describe.configure({ mode: 'serial' });

test.beforeAll(async ({ context }) => {
extensionPage = context.pages()[1]
})

test.describe('Test 1', () => {
let page
test.beforeAll(async ({ context }) => {
page = createPageModelObject()
})

test('should do stuff', async () => {

})
})

test.describe('Test 2', () => {
let page
test.beforeAll(async ({ context }) => {
page = createPageModelObject()
})

test('should do stuff', async () => {

})
})

The problem with the above is that my browser tears down and setups up in each new describe + beforeAll block. Ideally this wouldn't be the case so that I could reuse a single extension window.

Issue 2:
Context:

Playwright Version: 1.18.1

Operating System: Windows 10

Node.js version: 16.13.0

Browser: Chromium

Extra: Chromium is run with --no-sandbox

Describe the bug

When run normally, the browser is accepting the Set-Cookie header. However, when run with show set to false (i.e. headless mode), the browser ignores the Set-Cookie header.

This bug differs from its tens of near-duplicates because:

It affects first-party as well as third-party cookies.

It's verified to only happen in headless mode.

It's not because of headless detection. Packet interception shows that the Set-Cookie header is being sent by the server.

Workaround

The magical incantation --disable-features=ImprovedCookieControls,ImprovedCookieControlsForThirdPartyCookieBlocking,SameSiteByDefaultCookies,CookiesWithoutSameSiteMustBeSecure makes the symptoms go away, at least for right now.