Skip to content

Commit e50ce4c

Browse files
authored
fix(storageState): enhance error handling for storage state setting (microsoft#36781)
1 parent 6c23a74 commit e50ce4c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/playwright-core/src/server/browserContext.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Debugger } from './debugger';
2525
import { DialogManager } from './dialog';
2626
import { BrowserContextAPIRequestContext } from './fetch';
2727
import { mkdirIfNeeded } from './utils/fileUtils';
28+
import { rewriteErrorMessage } from '../utils/isomorphic/stackTrace';
2829
import { HarRecorder } from './har/harRecorder';
2930
import { helper } from './helper';
3031
import { SdkObject } from './instrumentation';
@@ -644,6 +645,9 @@ export abstract class BrowserContext extends SdkObject {
644645
}
645646
await page.close();
646647
}
648+
} catch (error) {
649+
rewriteErrorMessage(error, `Error setting storage state:\n` + error.message);
650+
throw error;
647651
} finally {
648652
this._settingStorageState = false;
649653
}

tests/library/browsercontext-storage-state.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ it('should set local storage', async ({ contextFactory }) => {
7474
await context.close();
7575
});
7676

77+
it('should report good error if the url is not valid', async ({ contextFactory }) => {
78+
const error = await contextFactory({
79+
storageState: {
80+
cookies: [],
81+
origins: [
82+
{
83+
origin: 'foo',
84+
localStorage: [{
85+
name: 'name1',
86+
value: 'value1'
87+
}]
88+
},
89+
]
90+
}
91+
}).catch(e => e);
92+
expect(error.message).toContain('browser.newContext: Error setting storage state:');
93+
expect(error.message).toContain('foo');
94+
});
95+
7796
it('should round-trip through the file', async ({ contextFactory }, testInfo) => {
7897
const context = await contextFactory();
7998
const page1 = await context.newPage();

0 commit comments

Comments
 (0)