Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web worker error on import #3824

Open
GeneriicName opened this issue Sep 9, 2024 · 0 comments
Open

Web worker error on import #3824

GeneriicName opened this issue Sep 9, 2024 · 0 comments

Comments

@GeneriicName
Copy link

using the following sample code, i get an error immedietly when creating a worker

importScripts('https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js');
importScripts('https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js');

self.onmessage = function(event) {
    
};
VM7:1 Uncaught SyntaxError: "[object Object]" is not valid JSON 
   at JSON.parse (<anonymous>) 
   at prism.js:1157:24
 (anonymous)	@	prism.js:1157

before proforming any other action but importing the lib, it does highlight though after that, but when ever i use the worker same error keeps popping up

the full web worker script

importScripts('https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js');
importScripts('https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js');

self.onmessage = function(event) {
    const { content } = event.data;

    if (typeof content === 'string') {
        try {
            const highlightedCode = Prism.highlight(content, Prism.languages.javascript, 'javascript');
            self.postMessage(highlightedCode);
        } catch (error) {
            self.postMessage({ error: error.message, stack: error});
        }
    } else {
        self.postMessage({ error: 'Invalid content type' });
    }
};

any help will be gratly appricated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant