-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Exception when run in a WebWorker #1059
Comments
Can you provide some example code to reproduce the issue? Prism should be able to be used in a Worker. I just tested the following code, that works: var worker = new Worker('prism.js');
worker.onmessage = function(evt) {
console.log(evt.data);
// Displays <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span><span class="token punctuation">></span></span>
};
worker.postMessage(JSON.stringify({
language: 'markup',
code: '<span>'
})); |
@Golmote Look at the code linked from the report. It is quite obvious that it unconditionally handles any messages. That makes Prism.js in its current form unsuitable as a library in a Web worker (opposed to being the sole and only script running in the worker, as the code currently assumes). I worked around the issue in my own project by temporarily clearing the Ideally there would be a global flag to disable this, e.g. |
Could we add a public method to detach the message listener? Would this help? |
Ideally the |
You can also check the format of the incoming message and do nothing if it cannot be processed. |
The |
@Rob--W True that. There are ways to hack this around (like passing arguments via location) but they are not stable. |
Trying to execute
Prism.highlight(...)
in a WebWorker results in an error being throw from Prism.It looks like the following code is the culprit. It assumes that if Prism is run in a Worker it will a be Worker created by itself using the
async
option and the message will have the Prism contract being a JSON withlanguage
,code
andimmediateClose
fields.The text was updated successfully, but these errors were encountered: