Firefox content script does not allow clearTimeout and clearInterval to be called in a non-global context
See original GitHub issue🐞 bug report
Affected Package
The issue is caused by package @angular/zone.js
Is this a regression?
No
Description
A clear and concise description of the problem...When calling clearInterval
or clearTimeout
in the restricted context of a content script on Firefox with ZoneJS initialized, the call will error out because the function is no longer being called in the context of the window
.
🔬 Minimal Reproduction
Difficult to recreate, I’ll update my previous testing repo later today.
🔥 Exception or Error
ERROR TypeError: "'clearInterval' called on an object that does not implement interface Window."
🌍 Your Environment
Angular Version:
Angular CLI: 9.1.1
Node: 12.16.3
OS: darwin x64
Angular: 9.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.901.1
@angular-devkit/build-angular 0.901.1
@angular-devkit/build-optimizer 0.901.1
@angular-devkit/build-webpack 0.901.1
@angular-devkit/core 9.1.1
@angular-devkit/schematics 9.1.1
@angular/cdk 9.2.1
@ngtools/webpack 9.1.1
@schematics/angular 9.1.1
@schematics/update 0.901.1
rxjs 6.5.5
typescript 3.8.3
webpack 4.42.0
Anything else relevant?
This applies only to Firefox Web Extension content scripts, a temporary patch to work around this issue is below, placed after the zone.js import in polyfills.ts
:
const patchedClearTimeout = window.clearTimeout;
window.clearTimeout = function(...args) {
return patchedClearTimeout.apply(window, args);
};
const patchedClearInterval = window.clearInterval;
window.clearInterval = function(...args) {
return patchedClearInterval.apply(window, args);
};
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
setTimeout() - Web APIs - MDN Web Docs
Timeouts are cancelled using clearTimeout() . To call a function repeatedly (e.g., every N milliseconds), consider using setInterval() . Non- ...
Read more >setInterval not called in tab content-script - Stack Overflow
Use this var { setInterval, clearInterval } = require("sdk/timers"); console.log("foo"); var id = setInterval(function() ...
Read more >WindowTimers.setTimeout()
Timeouts are cancelled using window.clearTimeout() . To call a function repeatedly (e.g., every N milliseconds), consider using window.
Read more >Cooperative asynchronous JavaScript: Timeouts and intervals
We can give our function a name, and can even define it somewhere ... clearTimeout() to clear setTimeout() entries and clearInterval() to ...
Read more >Window clearTimeout() Method - W3Schools
myTimeout = setTimeout(function, milliseconds);. Then you can to stop the execution by calling clearTimeout():. clearTimeout(myTimeout); ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@spaceribs, please provide a reproduce repo, and I would like to do some research.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.