Need workaround for calling alert() from background script

允我心安 提交于 2019-11-30 19:31:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!