问题
Calling alert() from the background script is allowed in Google's Chrome, but not in Firefox (WebExtensions) which I am porting my Chrome extension to.
So, I need a workaround to get an alert dialog up. I'm not asking for anything else other than THE alert dialog.
Sending a message to a content script to call alert() will not suffice since no content scripts may be loaded at the time the alert call is needed.
回答1:
My workaround is to save the alert code in a string like:
var alertWindow = 'alert(message)';
and let the background script inject that code like:
browser.tabs.executeScript({code : alertWindow});
来源:https://stackoverflow.com/questions/38950281/need-workaround-for-calling-alert-from-background-script