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.