@@ -49,7 +49,7 @@ await page1.EvaluateAsync(@"() =>
4949 string storage = await Context . StorageStateAsync ( ) ;
5050
5151 // TODO: think about IVT-in the StorageState and serializing
52- string expected = @"{""cookies"":[],""origins"":[{""origin"":""https://www.domain.com"",""localStorage"":[{""name"":""name2"",""value"":""value2""}]},{""origin"":""https://www.example.com"",""localStorage"":[{""name"":""name1"",""value"":""value1""}]}]}" ;
52+ string expected = @"{""cookies"":[],""origins"":[{""origin"":""https://www.domain.com"",""localStorage"":[{""name"":""name2"",""value"":""value2""}],""indexedDB"":[] },{""origin"":""https://www.example.com"",""localStorage"":[{""name"":""name1"",""value"":""value1""}],""indexedDB"":[ ]}]}" ;
5353 Assert . AreEqual ( expected , storage ) ;
5454 }
5555
@@ -82,14 +82,30 @@ await page1.RouteAsync("**/*", (route) =>
8282 } ) ;
8383
8484 await page1 . GotoAsync ( "https://www.example.com" ) ;
85- await page1 . EvaluateAsync ( @"() =>
85+ await page1 . EvaluateAsync ( @"async () =>
8686 {
8787 localStorage['name1'] = 'value1';
8888 document.cookie = 'username=John Doe';
89+
90+ await new Promise((resolve, reject) => {
91+ const openRequest = indexedDB.open('db', 42);
92+ openRequest.onupgradeneeded = () => {
93+ openRequest.result.createObjectStore('store');
94+ };
95+ openRequest.onsuccess = () => {
96+ const request = openRequest.result.transaction('store', 'readwrite')
97+ .objectStore('store')
98+ .put('foo', 'bar');
99+ request.addEventListener('success', resolve);
100+ request.addEventListener('error', reject);
101+ };
102+ });
103+
104+ return document.cookie;
89105 }" ) ;
90106 using var tempDir = new TempDirectory ( ) ;
91107 string path = Path . Combine ( tempDir . Path , "storage-state.json" ) ;
92- string storage = await Context . StorageStateAsync ( new ( ) { Path = path } ) ;
108+ string storage = await Context . StorageStateAsync ( new ( ) { IndexedDB = true , Path = path } ) ;
93109 Assert . AreEqual ( storage , File . ReadAllText ( path ) ) ;
94110
95111 await using var context = await Browser . NewContextAsync ( new ( ) { StorageStatePath = path } ) ;
@@ -102,6 +118,22 @@ await page2.RouteAsync("**/*", (route) =>
102118 await page2 . GotoAsync ( "https://www.example.com" ) ;
103119 Assert . AreEqual ( "value1" , await page2 . EvaluateAsync < string > ( "localStorage['name1']" ) ) ;
104120 Assert . AreEqual ( "username=John Doe" , await page2 . EvaluateAsync < string > ( "document.cookie" ) ) ;
121+
122+ var idbValue = await page2 . EvaluateAsync < string > ( @"
123+ () => {
124+ return new Promise((resolve, reject) => {
125+ const openRequest = indexedDB.open('db', 42);
126+ openRequest.addEventListener('success', () => {
127+ const db = openRequest.result;
128+ const transaction = db.transaction('store', 'readonly');
129+ const getRequest = transaction.objectStore('store').get('bar');
130+ getRequest.addEventListener('success', () => resolve(getRequest.result));
131+ getRequest.addEventListener('error', () => reject(getRequest.error));
132+ });
133+ openRequest.addEventListener('error', () => reject(openRequest.error));
134+ });
135+ }" ) ;
136+ Assert . AreEqual ( "foo" , idbValue ) ;
105137 }
106138
107139 [ PlaywrightTest ( "browsercontext-storage-state.spec.ts" , "should capture cookies" ) ]
0 commit comments