Skip to content

Commit 433aa08

Browse files
committed
Optimize download document logic
1 parent 9853772 commit 433aa08

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

docs/packages/download-collector-crx.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,21 @@ async function runTest() {
120120
// Click download button
121121
await driver.findElement(By.id('download-button')).click();
122122

123-
// Wait for download to complete (you might need a custom wait)
124-
await driver.sleep(2000);
123+
// Wait for download to complete by polling localStorage
124+
let downloadsStr;
125+
let downloads;
126+
const timeout = Date.now() + 15000; // 15 seconds timeout
127+
do {
128+
downloadsStr = await driver.executeScript(
129+
'return localStorage.getItem("_DOWNLOADS_");'
130+
);
131+
downloads = downloadsStr ? JSON.parse(downloadsStr) : [];
132+
if (downloads.length > 0 && downloads[0].state === 'complete') break;
133+
await driver.sleep(500);
134+
} while (Date.now() < timeout);
125135

126136
// Get download information
127-
const downloadsStr = await driver.executeScript(
128-
'return localStorage.getItem("_DOWNLOADS_");'
129-
);
137+
// downloadsStr already fetched above
130138

131139
const downloads = JSON.parse(downloadsStr);
132140
console.log('Downloads:', downloads);

0 commit comments

Comments
 (0)