tabs onUpdated event not detected ?

Hi,

I am trying to test along the tabs onUpdated event on a simple web extension/addon under Chrome. I used the Safari XCRUN converter !

What I am trying to do is :

1- Open new tab on Google Scholar with set prefs params, from "options.js" script (code below)

2- Listen for tab to be updated and ready (e.g. tab status is complete)

3 - Then, inject a content script that will simulate the user click on save button

4- Then wait 1,5s (for GS tab to reload and finish saving) and remove the listener

5- Finally close this GS tab and back to extension Options page tab.

    // Detect browser language
    const gsUrl = currentBrowser.i18n.getUILanguage().includes("fr")
      ? GSCHOLAR_SET_PREFS_FR_URL
      : GSCHOLAR_SET_PREFS_COM_URL;
    // Listener to detect when the GS tab has finished loading
    const gsTabListener = (tabId, changeInfo, tabInfo) => {
      if (changeInfo.url && changeInfo.url.startsWith(GSCHOLAR_HOST)) {
        currentBrowser.tabs.executeScript(
          tabId,
          {
            code: `document.getElementsByName("save")[0].click();`,
          },
          () => {
            currentBrowser.tabs.onUpdated.removeListener(gsTabListener);
            setTimeout(() => currentBrowser.tabs.remove(tabId), 1500);
          }
        );
      }
    };
    currentBrowser.tabs.onUpdated.addListener(gsTabListener); // Add tab listener
    currentBrowser.tabs.create({
      url: `${gsUrl}?inst=${gScholarInstIdList.join("&inst=")}&save=#2`,
      active: false,
    }); // Open GS tab according to browser language

The problem is that it works well on Chrome/Edge/Firefox, but not Safari : the GS tab isn't closed and nothing happens :-/

PS:

  • Of course tabs onUpdated event is well supported on Safari according to MDN.

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onUpdated

  • I have also tried webNavigation onCompleted event, but same !

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webNavigation/onCompleted

Thanks for your feedback.

Post not yet marked as solved Up vote post of mhabsaoui Down vote post of mhabsaoui
120 views

Replies

FYI, I am developing on :

  • MacBookAir under MacOS Monterey 12.4
  • Safari 15.4 (17613.2.7.18)
  • XCode 13.3.1 (13E500a)
  • My project is bundled with Webpack 5.68.0 (e.g. building the background + content + options assets files).

I really don't see what I am doing wrong (even in debug mode) 0_0

why wouldn't this tab event be intercepted ?

Any Help or Support please ?