Home > Back-end >  Firefox blocks Greasemonkey script that opens links with delay
Firefox blocks Greasemonkey script that opens links with delay

Time:01-06

I have a webpage with a series of links. I installed Greasemonkey script to click on each with a delay but Firefox blocks after only a few even though I have disabled the "Block Popups" option.

And they are not really popups anyway but just tabs, i.e complete pages.

the Greasemonkey script is

// ==UserScript==
// @name     AlbunackSubmitArtistLinksOnPage
// @version  1
// @grant    none
// @include  http://reports.albunack.net/mbartist_discogsartist_report2*.html
// ==/UserScript==

function delayedOpenLink(link)
{
    link.click();  
}

function check()
{
  var links = document.getElementsByName("link");
  var i=1;
  for(link of links)
  {
    setTimeout(delayedOpenLink, 5000 * i, link);
    i  ;
  }
}

setTimeout(check, 5000);

This is frustrating because it's my webpage and put a delay between each tab opening and I have disabled the popup blocking so why is Firefox still blocking my tabs

Also, I get a message saying Firefox prevented x Popups from opening but if you click on it there is only one option to open each one one by one, block popups, or manage popups (but they are already unblocked), but no option to allow popups.

Increasing delay from 5 seconds (5000) to 20 seconds (20000) allowed a few more to go through but not many more.

CodePudding user response:

How about GM_openInTab?

// ==UserScript==
// @name     AlbunackSubmitArtistLinksOnPage
// @version  1
// @grant    GM_openInTab
// @include  http://reports.albunack.net/mbartist_discogsartist_report2*.html
// ==/UserScript==

const delay = seconds => new Promise(resolve => setTimeout(resolve, seconds * 1e3));

async function check()
{
  const links = document.getElementsByName("link");

  for (const link of links) {
    await delay(5);
    GM_openInTab(link.href);
  }
}

setTimeout(check, 5000); // or check()

This will click every link on the page every 5 seconds. There are also some other improvements to your original script (const instead of var, async/await).

CodePudding user response:

The issue seems to be the number of tabs opened rather than the number of links opened. By this I mean that if I change the link to reuse the same tab with target="secondpage" instead of opening in a new tab with target="_blank" then Firefox doesn't complain.

I can only do this because when I open the link a Greasemonkey script kicks in and submits the page on the tab, so I no longer need the page. But I have to make sure there is enough time between opening each link for the Greasemonkey script to complete before the next link is opened.

  •  Tags:  
  • Related