Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

How to register a web worker in a custom extension?

Topic Labels: Custom Extensions
1264 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Jake_Wilson
6 - Interface Innovator
6 - Interface Innovator

I'm getting a CORS error when instantiating a Worker.  What do I need to do to avoid this CORS error when instantiating a Worker?  

"Failed to construct 'Worker': Script at 'https://localhost:9000/worker.ts' cannot be accessed from origin 'https://devblock---t-vjm-s-v7-g-mvh-c-b-r--55q8cmv.alt.airtableblocks.com'."

 

 

import { initializeBlock } from "@airtable/blocks/ui";
import React from "react";

function HelloWorldTypescriptApp() {
    const useWebWorker = () => {
        const worker = new Worker("worker.ts"); // <-- throws error mentioned above
        worker.postMessage("foo");
    };


    return <button onClick={useWebWorker}>Click me</button>;
}

initializeBlock(() => <HelloWorldTypescriptApp />);

 

source code: https://github.com/jacobwilson41/airtable_web_worker_example/tree/main/frontend

 

2 Replies 2
Jake_Wilson
6 - Interface Innovator
6 - Interface Innovator

Found this in their docs

"Our Blocks SDK allows users to build a custom extension with React.js. It gives teams the advantage of creating a custom interface that allows users to interact with the integration. Note: This code runs client-side and may require a CORS work-around."

Screenshot 2024-02-07 at 8.18.27 PM.png

 

Jake_Wilson
6 - Interface Innovator
6 - Interface Innovator

Screenshot 2024-02-08 at 7.54.14 AM.png

"Creating Web Workers is not allowed."