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.

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."
image

🌍 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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JiaLiPassioncommented, Jun 27, 2020

@spaceribs, please provide a reproduce repo, and I would like to do some research.

0reactions
angular-automatic-lock-bot[bot]commented, Aug 24, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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