Closed fregante closed 3 years ago
I found out why: tab.url
is an empty string for some reason. activeTab
should fill that in.
If this can be fixed, I think this module is still the easiest way to build cross-browser extensions since we don't have to customize the Safari build.
tab.url
is empty because apparently context menu clicks don't "activate" the tab (activeTab
permission). Left-clicking the browserAction first and then clicking the context menu item works, but that's awkward.
This bug might be solved by Safari in the near future or it might not.
I have 2 "solutions" for this:
tab.url
is missing from the event handler, instruct the user to click the icon first. This frees the developer from having to document this behavior.Perhaps I use both:
addDomainPermissionToggle({safari: false})
Example:
if (!tab.url) {
browser.tabs.executeScript(tab.id, {
code: 'alert("To enable this site:\\n1. Open Safari\'s Preferences\\n2. Visit the \\"Extensions\\" tab\\n3. Select this extension\\n4. Click \\"Edit Websites...\\"")'
});
return;
}
I think I found a workable solution!!
Step 1: Ask the user to try again.
if (!tab.url) {
chrome.tabs.executeScript({
code: `alert("Try again pretty please?")` // Alert doesn't work from background in Safari
});
return;
}
Step 2: Bind the request
/remove
functions to chrome.permissions
because that's how Safari likes them.
Step 3: Make sure that the menuitem checkmark is updated correctly when it fails
🥳
However webext-dynamic-content-scripts also needs to be fixed.
Safari has its own permission system which would replace this module
However this module should be updated to avoid adding a non-working context menu item