question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Illegal Invocation error when used in a web-worker

See original GitHub issue

When packing jsdom into a webworker via browserify + webworkify, this line throws an Illegal invocation error. This can be resolved by setting changing clearTimeout to window.clearTimeout in this line

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jdthorpecommented, Feb 9, 2017

Here’s a minimal reproducible example. Note that it only raises an error when browserified, but not when run in the Node. It’s a total edge-case due to the fact that MathJax calls clearTimeout() in some of the timer callbacks:

[example.js]

var document = require("jsdom").jsdom();
var window = document.defaultView;
window.console = console;
window.addEventListener("error",function (event) {console.error(event.error.stack)});

var script = document.createElement("script");
script.type = "text/javascript";
script.innerHTML = `
var done = function(){ 
    clearTimeout(t); 
    }
var t = setTimeout(done,100)
` 
script.onerror = function(err){
    console.error("Script generated the following error:",err)
}
document.head.appendChild(script)

Then call:

browserify example.js -o bundle.js

then open example.html in chrome, firefox, or safari

[example.html]
    
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Error on the Console</title>
    <script src="file:///path/to/bundle.js"></script>
</head>
<body>
</body>
</html>

and something like this will be displayed on the console:

TypeError: Illegal invocation at Window.stopTimer (example-bundle.js:63033) at Window.done (about:blank:4) at callback (example-bundle.js:63019)

0reactions
domeniccommented, Feb 8, 2017

Thanks for the investigation, but it really isn’t helpful to suggest lines to change. What we need is a small, preferably 10-20 line reproduction case that we can add to our test suite to ensure that this feature continues to work going forward, and use to debug the best way to proceed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dart-sass in Web Worker: `Error: Illegal invocation`
This happens when any importer (even a "noop" importer) is added. Executing this code on the main thread (using just require ) works...
Read more >
"Illegal invocation" errors in JavaScript - Matias Kinnunen
An "illegal invocation" error is thrown when calling a function whose this keyword doesn't refer to the object where it originally did. In...
Read more >
JavaScript Errors Try Catch Throw - W3Schools
The catch statement defines a code block to handle any error. ... Identifier) Error. A URIError is thrown if you use illegal characters...
Read more >
Uncaught (in promise) TypeError: Illegal invocation
Uncaught (in promise) TypeError: Illegal invocation error using jQuery ajax code. To fix the error, try adding `processData: false` and ...
Read more >
TestCafe v1.11.0 Released | Framework | Release Notes
TestCafe raises this error when at least one local or remote browser was not ... Fixed an error ( TypeError: Illegal invocation )...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found