MCPcopy Create free account
hub / github.com/cfworker/cfworker / setWorkerCode

Method setWorkerCode

packages/dev/src/worker-host.js:93–128  ·  view source on GitHub ↗

* @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 = []
  )

Source from the content-addressed store, hash-verified

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;

Callers 3

runTestsMethod · 0.80
executeMethod · 0.80
updateMethod · 0.80

Calls 3

executeWorkerScriptFunction · 0.85
progressMethod · 0.45
successMethod · 0.45

Tested by

no test coverage detected