setTimeout and setInterval silently fails in extensions on csp-restricted websites

Confirmed Issue #8241022 • Assigned to Scott S.

Details

Created
Jul 21, 2016
Privacy
This issue is public.
Reports
Reported by 0 people

Sign in to watch or report this issue.

Steps to reproduce

  1. Create an extension with the following content script:

 

setTimeout(function() { alert(“setTimeout”); }, 33);

 

  1. Enable the extension

  2. Go to github.com

 

Expected: the message shows up

Actual: it doesn’t

 

Workaround:

// this is a polyfill for setTimeout and setInterval, for when the csp policy blocks eval/setTimeout/setInterval

void function() {

 var stm = window.setTimeout;

 var sti = window.setInterval;

 var clm = window.clearTimeout;

 var cli = window.clearInterval;

 setTimeout(function() {

  // restoring proper timeouts

  window.setTimeout = stm;

  window.setInterval = sti;

  window.clearTimeout = clm;

  window.clearInterval = cli;

 }, 0);

}();

window.setTimeout = function(x,t?,…args) {

 var time = performance.now() + t|0;

 function runIfTimeHasCome() {

  if(performance.now() > time) {

   x.apply(window, args);

  } else {

   handle = requestAnimationFrame(runIfTimeHasCome);

  }

 }

 var handle = requestAnimationFrame(runIfTimeHasCome);

 return (function() { cancelAnimationFrame(handle); }) as any;

}

window.setInterval = function(x,t?,…args) {

 var time = performance.now() + t|0;

 function runIfTimeHasCome() {

  handle = requestAnimationFrame(runIfTimeHasCome)

  if(performance.now() > time) {

   time = time + t|0;

   x.apply(window, args);

  }

 }

 var handle = requestAnimationFrame(runIfTimeHasCome);

 return (function() { cancelAnimationFrame(handle); }) as any;

}

window.clearInterval = window.clearTimeout = function(t) {

 (t as any).call();

}

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Sermet I.”

      Changed Assigned To from “Sermet I.” to “Scott S.”

      Changed Status to “Confirmed”

      Changed Assigned To from “Scott S.” to “Scott L.”

      Changed Assigned To from “Scott L.” to “Sermet I.”

      Changed Assigned To from “Sermet I.” to “Scott S.”

    You need to sign in to your Microsoft account to add a comment.

    Sign in