Setinterval - Chrome Extension

Asked

Viewed 113 times

0

I’m in a little trouble,

I need to make a simple Alert to be displayed every 10 minutes for users, so I was asked to mount an Extension for Chrome since they use a dial in Chrome and it stays open all the time. The problem is this, I did manifest.json already, configured everything ok. I established the background.js for the scripts question but then the problem begins. (The extension is installed and working properly, my problem is with setInterval that seems not to work any longer)

I perform the following function.

var registraCPF = setInterval(alert('Registrar CPF'), 60000);

But with the 60000 being 1 minute it does not work, the Alert is not fired. Now when I put the Alert at 15000 or 3000 around.

var registraCPF = setInterval(alert('Registrar CPF'), 3000);

It works normally, someone knows why?

  • I don’t know if that’s the problem, but the code to be executed should be in quotes, like this: setInterval("alert('Registrar CPF')", 3000);

  • or var registraCPF = setInterval(()=>{alert('Registrar CPF')}, 3000);

  • Then, it displays error if quotation marks, displays "Refused to evaluate a string as Javascript because 'unsafe-Eval' is not allowed an source of script in the following Content Security Policy Directive: "script-src 'self' blob: filesystem: Chrome-Extension-Resource"

  • The second option also didn’t work with 1 minute. But with 3 seconds yes.

  • That’s right, actually using quotes is not recommended in setInterval, have to call a function as shown by Leandro.

  • Strange that. The thing is to test with other values until you find the maximum value that works. With this information I think it’s easier to find out why.

  • Thanks guys, I ended up creating in VBS, as it was only an Alert, I did not have to follow the idea of extension in Chrome, I applied in the GPO with task Schedule and the situation was resolved. By another means but it was. hahah

Show 2 more comments

1 answer

0

Try creating a function to show the alert():

var registraCPF = setInterval(function() {
        alert('Registrar CPF')
    }, 60000);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.