"use strict" directive to any of your code.
When the Use worker project property is checked, the Construct runtime is hosted in a Web Worker instead of in the DOM, and renders using an OffscreenCanvas. This is generally good for performance since the runtime can run independently of the browser main thread, which can be blocked by browser tasks like layout. However Web Workers have a reduced set of APIs available. Notably there are no
document objects available, and so the DOM cannot be directly accessed. However there are many other APIs still available, such as fetch (and the older XMLHttpRequest), IndexedDB, WebSocket and others - see Functions and classes available to workers for more details.
Accessing global scope
window object is used to refer to global scope, such as with
window.myGlobal = 1;. Note however that the
window object is not available in worker mode, so this won't work there.
The standard way of accessing the global scope is with
globalThis, such as with
globalThis.myGlobal = 1;. Since this is available in both the DOM and Web Workers, this code will work everywhere. Construct also polyfills this if it is missing, so there is no need to worry about browser support.
In a browser context you can also use
Note many older code examples across the web use an older style designed to support defunct browsers. For example many old code examples use
const are preferred. Bear this in mind when looking at other code examples, and note there may be modern features that can considerably simplify the code. It can be a good idea to update any code snippets you use in your projects to a modern style.
<script> tag. This means the
export keywords cannot be used. However dynamic imports, using the
await import(...) syntax, can still be used.
Note this only applies to the Construct engine - all other browser APIs are of course available for use.