I don't see why the runtime.onConnect event listener cannot be found. According to my code in background script, it should be initialised:
// Listener on sent parsed ID list from content script to be resolved
currentBrowser.runtime.onConnect.addListener((port) => {
port?.onMessage.addListener(async ({ parsedIdList }) => {
if (parsedIdList?.length > 0) {
// some logic here
}
});
});
Post
Replies
Boosts
Views
Activity
Hi,
Thanks for your support.
in order to be clearer, I'll give more accurate info:
Our add-on project web site (only usage and install doc): https://clickandread.inist.fr
The command I use to trigger a build with Xcrun:
xcrun safari-web-extension-converter --app-name "Click and Read" --bundle-identifier fr.inist.Click-and-read --swift --force --macos-only dist
Once the safari converter having launched Xcode with the generated project, I click on play to build this project. Then I get the add-on app built (with some errors ?) ready to be opened and activated in Safari.
Once my add-on enabled and set, I browse on a dedicated testing page, which should be injected with add-on content script (to display some C&R green buttons on the page).
Unfortunately, either on LTS or Preview Safari, I get the same error in console...
Please see attached screenshots.
Hi,
This safari extension behaviour seems related to mine on this post
After debugging I finally sloved this by noticing that in fact the events were triggered, but missed because of the availability and values of parameters passed into callabck (changeInfo, details) depending on the browser we're on.
So I switched from onUpdated to webNavigation.onCompleted API, which is better suited to our need (tab page fully loaded) and whose parameter is simple and consistent across browsers :-)
const uiLanguage = currentBrowser.i18n.getUILanguage().includes("fr")
? "fr"
: "com"; // Detect browser language
const gsUrl = `${GSCHOLAR_SETTINGS_HOST}.${uiLanguage}`;
// Listener to detect when the GS tab has finished loading
const gsTabListener = (details) => {
if (details && details.url && details.tabId) {
if (details.url.startsWith(`${gsUrl}/scholar_settings?`)) {
currentBrowser.tabs.executeScript(details.tabId, {
code: `document.getElementsByName("save")[0].click();`,
});
} else if (details.url.startsWith(`${gsUrl}/scholar?`)) {
currentBrowser.webNavigation.onCompleted.removeListener(
gsTabListener
);
currentBrowser.tabs.remove(details.tabId);
}
}
};
currentBrowser.webNavigation.onCompleted.addListener(gsTabListener); // Add GS tab listener
currentBrowser.tabs.create({
url: `${gsUrl}/scholar_settings?inst=${gScholarInstIdList.join(
"&inst="
)}&save=#2`,
active: false,
}); // Open GS tab according to browser language
Any Help or Support please ?