---
title: "importScriptInWorkers | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Variable importScriptInWorkers

importScriptInWorkers: (workerUrl: string) \=> Promise<void\[\]\>

#### Type Declaration

-   -   (workerUrl: string): Promise<void\[\]\>
    -   Allows loading javascript code in the worker thread. _Note_ that since this is using some very internal classes and flows it is considered experimental and can break at any point.
        
        It can be useful for the following examples:
        
        1.  Using `self.addProtocol` in the worker thread - note that you might need to also register the protocol on the main thread.
        2.  Using `self.registerWorkerSource(workerSource: WorkerSource)` to register a worker source, which should come with `addSourceType` usually.
        3.  using `self.actor.registerMessageHandler` to override some internal worker operations
        
        #### Parameters
        
        -   workerUrl: string
            
            the worker url e.g. a url of a javascript file to load in the worker
            
        
        #### Returns Promise<void\[\]\>
        
        #### Example[](#example)
        
        ```typescript
        // below is an example of sending a js file to the worker to load the method there
        // Note that you'll need to call the global function `addProtocol` in the worker to register the protocol there.
        // add-protocol-worker.js
        async function loadFn(params, abortController) {
            const t = await fetch(`https://${params.url.split("://")[1]}`);
            if (t.status == 200) {
                const buffer = await t.arrayBuffer();
                return {data: buffer}
            } else {
                throw new Error(`Tile fetch error: ${t.statusText}`);
            }
        }
        self.addProtocol('custom', loadFn);
        
        // main.js
        importScriptInWorkers('add-protocol-worker.js');
        ```
