Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(storageState): enhance error handling for storage state setting (#36781)
Max Schmitte50ce4c7fa5f
diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.tsindex 00ecf1792d..48668e6314 100644--- a/packages/playwright-core/src/server/browserContext.ts+++ b/packages/playwright-core/src/server/browserContext.ts@@ -25,6 +25,7 @@ import { Debugger } from './debugger';import { DialogManager } from './dialog';import { BrowserContextAPIRequestContext } from './fetch';import { mkdirIfNeeded } from './utils/fileUtils';+import { rewriteErrorMessage } from '../utils/isomorphic/stackTrace';import { HarRecorder } from './har/harRecorder';import { helper } from './helper';import { SdkObject } from './instrumentation';@@ -644,6 +645,9 @@ export abstract class BrowserContext extends SdkObject {}await page.close();}+ } catch (error) {+ rewriteErrorMessage(error, `Error setting storage state:\n` + error.message);+ throw error;} finally {this._settingStorageState = false;}diff --git a/tests/library/browsercontext-storage-state.spec.ts b/tests/library/browsercontext-storage-state.spec.tsindex 972453e1b2..4f4fca6cee 100644--- a/tests/library/browsercontext-storage-state.spec.ts+++ b/tests/library/browsercontext-storage-state.spec.ts@@ -74,6 +74,25 @@ it('should set local storage', async ({ contextFactory }) => {await context.close();});+it('should report good error if the url is not valid', async ({ contextFactory }) => {+ const error = await contextFactory({+ storageState: {+ cookies: [],+ origins: [+ {+ origin: 'foo',+ localStorage: [{+ name: 'name1',+ value: 'value1'+ }]+ },+ ]+ }+ }).catch(e => e);+ expect(error.message).toContain('browser.newContext: Error setting storage state:');+ expect(error.message).toContain('foo');+});+it('should round-trip through the file', async ({ contextFactory }, testInfo) => {const context = await contextFactory();const page1 = await context.newPage();