Issue 1:
System info

Playwright Version: 1.32.1

Operating System: Ubuntu 22.04.2 LTS

Browser: Desktop Safari

Other info: Only fails in CI (have tried Github Actions and also Azure Devops). This works locally.

Source code

I provided exact source code that allows reproducing the issue locally.

The webpage loaded is a simple HTML page (served via firebase hosting emulator)

Config file

// playwright.config.ts
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
retries: 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'line',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
baseURL: "http://localhost:5000",
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

// README: current apparent bug in Playwright+Firefox when using a service worker and requesting a cross-domain HTTPS url (e.g. the firebase libraries from gstatic.com)
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ..devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});

Test file (self-contained)

test("Webkit bug", async ({ context, page }) => {

await page.goto("/");
const storageState = await context.storageState();
console.log(storageState);
await page.evaluate(() => localStorage.setItem("dev-mode", true));
const storageState2 = await context.storageState();
console.log(storageState2);
await page.reload();

});

Steps

[Run the test]

Expected

Test passes

Actual

Running script: DEBUG=pw:browser* npx playwright test

Running 2 tests using 1 worker

[1/2] [chromium] › login.spec.js:36:5 › Webkit bug
[chromium] › login.spec.js:36:5 › Webkit bug

pw:browser <launching> /home/runner/.cache/ms-playwright/chromium-1055/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-2d3gMB --remote-debugging-pipe --no-startup-window +0ms
pw:browser <launched> pid=4469 +4ms

pw:browser [pid=4469][err] [0406/093140.969637:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable. +2s

pw:browser [pid=4469][err] [0406/093141.009862:WARNING:sandbox_linux.cc(393)] InitializeSandbox() called with multiple threads in process gpu-process. +40ms

i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:41 +0000] "GET / HTTP/1.1" 200 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.29 Safari/537.36"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:41 +0000] "GET /css/main.css HTTP/1.1" 200 - "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.29 Safari/537.36"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:41 +0000] "GET /js/main.js HTTP/1.1" 200 - "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.29 Safari/537.36"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:41 +0000] "GET /img/PA-with-text-logo.svg HTTP/1.1" 200 - "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.29 Safari/537.36"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:41 +0000] "GET /img/landing.jpg HTTP/1.1" 200 2995[35](https://github.com/pocketangler/jackass/actions/runs/4627475169/jobs/8185434488#step:8:36) "http://localhost:5000/css/main.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.29 Safari/537.36"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:41 +0000] "GET /sw.js HTTP/1.1" 404 492 "http://localhost:5000/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/112.0.5615.29 Safari/537.36"
{ cookies: [], origins: [] }

{
cookies: [],
origins: [ { origin: 'http://localhost:5000', localStorage: [Array] } ]
}

i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:41 +0000] "GET / HTTP/1.1" 200 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.29 Safari/537.36"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:41 +0000] "GET /sw.js HTTP/1.1" 404 492 "http://localhost:5000/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/112.0.5615.29 Safari/537.36"
pw:browser [pid=4469] <gracefully close start> +1s

pw:browser [pid=4469] <process did exit: exitCode=0, signal=null> +19ms

pw:browser [pid=4469] starting temporary directories cleanup +1ms
pw:browser [pid=4469] finished temporary directories cleanup +4ms

pw:browser [pid=4469] <gracefully close end> +0ms

[2/2] [webkit] › login.spec.js:36:5 › Webkit bug
[webkit] › login.spec.js:36:5 › Webkit bug
pw:browser <launching> /home/runner/.cache/ms-playwright/webkit-1811/pw_run.sh --inspector-pipe --headless --no-startup-window +0ms

pw:browser <launched> pid=5147 +4ms

pw:browser [pid=5147][err] Could not determine the accessibility bus address +2s

i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:49 +0000] "GET / HTTP/1.1" 200 - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:49 +0000] "GET /css/main.css HTTP/1.1" 200 - "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:49 +0000] "GET /js/main.js HTTP/1.1" 200 - "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:49 +0000] "GET /img/PA-with-text-logo.svg HTTP/1.1" 200 - "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:49 +0000] "GET /img/landing.jpg HTTP/1.1" 200 299535 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
i hosting: 127.0.0.1 - - [06/Apr/2023:09:31:49 +0000] "GET /sw.js HTTP/1.1" 404 492 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
{ cookies: [], origins: [] }

pw:browser [pid=5147][err] EGLDisplay Initialization failed: EGL_NOT_INITIALIZED +7s

pw:browser [pid=5147][err] /home/runner/.cache/ms-playwright/webkit-1811/pw_run.sh: line 21: 5152 Segmentation fault (core dumped) WEBKIT_FORCE_COMPLEX_TEXT="1" "$MINIBROWSER" "$@" +0ms

pw:browser [pid=5147] <process did exit: exitCode=1[39](https://github.com/pocketangler/jackass/actions/runs/4627475169/jobs/8185434488#step:8:40), signal=null> +1ms
pw:browser [pid=5147] starting temporary directories cleanup +0ms

pw:browser [pid=5147] finished temporary directories cleanup +5ms

1) [webkit] › login.spec.js:36:5 › Webkit bug ────────────────────────────────────────────────────

Error: browserContext.storageState: Browser closed.
==================== Browser output: ====================
<launching> /home/runner/.cache/ms-playwright/webkit-1811/pw_run.sh --inspector-pipe --headless --no-startup-window
<launched> pid=5147
[pid=5147][err] Could not determine the accessibility bus address
[pid=5147][err] EGLDisplay Initialization failed: EGL_NOT_INITIALIZED
[pid=5147][err] /home/runner/.cache/ms-playwright/webkit-1811/pw_run.sh: line 21: 5152 Segmentation fault (core dumped) WEBKIT_FORCE_COMPLEX_TEXT="1" "$MINIBROWSER" "$@"
[pid=5147] <process did exit: exitCode=139, signal=null>
[pid=5147] starting temporary directories cleanup
[pid=5147] finished temporary directories cleanup

[40](https://github.com/pocketangler/jackass/actions/runs/4627475169/jobs/8185434488#step:8:41) | console.log(storageState);
[41](https://github.com/pocketangler/jackass/actions/runs/4627475169/jobs/8185434488#step:8:42) | await page.evaluate(() => localStorage.setItem("dev-mode", true));
> [42](https://github.com/pocketangler/jackass/actions/runs/4627475169/jobs/8185434488#step:8:43) | const storageState2 = await context.storageState();
| ^
[43](https://github.com/pocketangler/jackass/actions/runs/4627475169/jobs/8185434488#step:8:44) | console.log(storageState2);
[44](https://github.com/pocketangler/jackass/actions/runs/4627475169/jobs/8185434488#step:8:45) | await page.reload();
[45](https://github.com/pocketangler/jackass/actions/runs/4627475169/jobs/8185434488#step:8:46) |

at /home/runner/work/jackass/jackass/test/e2e/tests/login.spec.js:42:41

1 failed
[webkit] › login.spec.js:36:5 › Webkit bug ─────────────────────────────────────────────────────
1 passed (13.3s)
⚠ Script exited unsuccessfully (code 1)
i emulators: Shutting down emulators.
i functions: Stopping Functions Emulator
i hosting: Stopping Hosting Emulator
i firestore: Stopping Firestore Emulator
i auth: Stopping Authentication Emulator
i eventarc: Stopping Eventarc Emulator
i hub: Stopping emulator hub
i logging: Stopping Logging Emulator

Error: Script "DEBUG=pw:browser* npx playwright test" exited with code 1
Error: Process completed with exit code 1.

Issue 2:
Hello.

I am trying to deal with saving authentication state between my tests.

I am going with approach where I have beforeAll hook where I log in to application, then save the state with context().storageState():

BeforeAll(async function () {
global.browser = await chromium.launch({
headless: false,
});
global.page = await global.browser.newPage();
await page.goto('https://mypage.com');
***some authentication steps ***
await page.context().storageState({ path: 'storageState.json' });
page.close();
});

after this action storageState.json file has this structure (no auth info that's fine):

{
"cookies": [],
"origins": [
{
"origin": "https://mypage.com",
"localStorage": [
{
"name": "signedOut",
"value": "false"
}
]
}
]
}

next I use "Before" hook to set up each test:

Before(async function (scenario) {
global.context = await global.browser.newContext({
storageState: 'storageState.json'
});

global.page = await global.context.newPage();
await page.goto('https://mypage.com');
});

and then I start my test cases.

The issue is that for each test, there is additional page that open for url in storageState.json file so for the user it looks like this:

one page opens (this is because of using storageState file)

redirection to mypage.com (this is because of 'origin' in storageState)

page close

page open again (this is because of newPage() in Before)

redirection to mypage.com (this is from 'Before' goto step)

test proceed

I think first 3 steps should not happen.

I did some research and if I remove value from origin parameter then this first page will not open and everything is fine.

Also if I remove storageState: 'storageState.json' from 'Before' then this issue is gone but I need this state in context for each test.

I think the similar issue was here but no answers were given:

https://stackoverflow.com/questions/70878170/playwright-browsercontext-storagestate-opens-all-visited-tabs