Skip to content

Commit

Permalink
allow to use urls in scriptPath
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed May 14, 2024
1 parent 2e77044 commit 12fd503
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,14 +943,23 @@ window.SERVER_USE_HTTPS = ${this.serverUseHttps};
if (!filePath.trim()) {
continue
}
if (!fs.existsSync(filePath)) {
log.warn(`custom script not found: ${filePath}`)
continue
if (filePath.startsWith('http')) {
log.debug(`loading custom script from url: ${filePath}`)
const res = await downloadUrl(filePath)
if (!res?.data) {
throw new Error(`Failed to download script from: ${filePath}`)
}
await page.evaluateOnNewDocument(res.data)
} else {
if (!fs.existsSync(filePath)) {
log.warn(`custom script not found: ${filePath}`)
continue
}
log.debug(`loading custom script from file: ${filePath}`)
await page.evaluateOnNewDocument(
await fs.readFileSync(filePath, 'utf8'),
)
}
log.debug(`loading custom script: ${filePath}`)
await page.evaluateOnNewDocument(
await fs.readFileSync(filePath, 'utf8'),
)
}
}
}
Expand Down

0 comments on commit 12fd503

Please sign in to comment.