* @param {string} code The worker script. * @param {string} sourcePathname Where to list the script in the chrome devtools sources tree. * @param {string[]} globals Names of additional globals to expose. * @param {Record | null} staticContentManifest Workers site manifest.
(
code,
sourcePathname = '/worker.js',
globals = [],
staticContentManifest = null,
kvNamespaces = []
)
| 91 | * @param {import('./kv.js').KVNamespaceInit[]} kvNamespaces |
| 92 | */ |
| 93 | async setWorkerCode( |
| 94 | code, |
| 95 | sourcePathname = '/worker.js', |
| 96 | globals = [], |
| 97 | staticContentManifest = null, |
| 98 | kvNamespaces = [] |
| 99 | ) { |
| 100 | const startTime = Date.now(); |
| 101 | logger.progress('Updating worker script...'); |
| 102 | const page = await this.pageReady; |
| 103 | await page.evaluate( |
| 104 | async ( |
| 105 | code, |
| 106 | sourcePathname, |
| 107 | globals, |
| 108 | staticContentManifest, |
| 109 | kvNamespaces |
| 110 | ) => { |
| 111 | const { executeWorkerScript } = await import('./runtime/index.js'); |
| 112 | await executeWorkerScript( |
| 113 | code, |
| 114 | sourcePathname, |
| 115 | globals, |
| 116 | staticContentManifest, |
| 117 | kvNamespaces |
| 118 | ); |
| 119 | }, |
| 120 | code, |
| 121 | sourcePathname, |
| 122 | globals, |
| 123 | staticContentManifest, |
| 124 | kvNamespaces |
| 125 | ); |
| 126 | logger.success('Worker script updated', Date.now() - startTime); |
| 127 | this.emit('worker-updated'); |
| 128 | } |
| 129 | |
| 130 | async reloadPage() { |
| 131 | const page = await this.pageReady; |