Need workaround for calling alert() from background script












2














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.










share|improve this question






















  • The way that you have worded this it sounds like you will accept no solution other than the actual alert() dialog, not even something that looks and feels like it. If so, then you are SOL. The text which is output in the console "alert() is not supported in background windows; please use console.log instead." is clear. alert() is not supported in background scripts. If you want more information, you might check Bug 1203394 - alert() does not work in background scripts which is RESOLVED FIXED with this console output as the result.
    – Makyen
    Aug 15 '16 at 14:26










  • To be clear: Will you accept a substitute which works in both Firefox and Google Chrome which comes close to looking and acting like an alert()?
    – Makyen
    Aug 15 '16 at 14:28










  • Also to be clear: it is not acceptable to you to have as a solution that a content script be loaded to accomplish the alert(). This is not saying send a message to an already loaded content script, but actually loading one specifically to handle this issue. This is not an acceptable solution to you, correct?
    – Makyen
    Aug 15 '16 at 14:32










  • @Makyen Give it a shot.
    – AlJo
    Aug 15 '16 at 16:44






  • 1




    @Makyen, you're making rash unimaginative assumptions. If you can't answer the question as stated, don't let that bother you; just move along.
    – AlJo
    Aug 16 '16 at 2:52
















2














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.










share|improve this question






















  • The way that you have worded this it sounds like you will accept no solution other than the actual alert() dialog, not even something that looks and feels like it. If so, then you are SOL. The text which is output in the console "alert() is not supported in background windows; please use console.log instead." is clear. alert() is not supported in background scripts. If you want more information, you might check Bug 1203394 - alert() does not work in background scripts which is RESOLVED FIXED with this console output as the result.
    – Makyen
    Aug 15 '16 at 14:26










  • To be clear: Will you accept a substitute which works in both Firefox and Google Chrome which comes close to looking and acting like an alert()?
    – Makyen
    Aug 15 '16 at 14:28










  • Also to be clear: it is not acceptable to you to have as a solution that a content script be loaded to accomplish the alert(). This is not saying send a message to an already loaded content script, but actually loading one specifically to handle this issue. This is not an acceptable solution to you, correct?
    – Makyen
    Aug 15 '16 at 14:32










  • @Makyen Give it a shot.
    – AlJo
    Aug 15 '16 at 16:44






  • 1




    @Makyen, you're making rash unimaginative assumptions. If you can't answer the question as stated, don't let that bother you; just move along.
    – AlJo
    Aug 16 '16 at 2:52














2












2








2


2





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.










share|improve this question













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.







firefox-webextensions






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 15 '16 at 6:30









AlJo

619




619












  • The way that you have worded this it sounds like you will accept no solution other than the actual alert() dialog, not even something that looks and feels like it. If so, then you are SOL. The text which is output in the console "alert() is not supported in background windows; please use console.log instead." is clear. alert() is not supported in background scripts. If you want more information, you might check Bug 1203394 - alert() does not work in background scripts which is RESOLVED FIXED with this console output as the result.
    – Makyen
    Aug 15 '16 at 14:26










  • To be clear: Will you accept a substitute which works in both Firefox and Google Chrome which comes close to looking and acting like an alert()?
    – Makyen
    Aug 15 '16 at 14:28










  • Also to be clear: it is not acceptable to you to have as a solution that a content script be loaded to accomplish the alert(). This is not saying send a message to an already loaded content script, but actually loading one specifically to handle this issue. This is not an acceptable solution to you, correct?
    – Makyen
    Aug 15 '16 at 14:32










  • @Makyen Give it a shot.
    – AlJo
    Aug 15 '16 at 16:44






  • 1




    @Makyen, you're making rash unimaginative assumptions. If you can't answer the question as stated, don't let that bother you; just move along.
    – AlJo
    Aug 16 '16 at 2:52


















  • The way that you have worded this it sounds like you will accept no solution other than the actual alert() dialog, not even something that looks and feels like it. If so, then you are SOL. The text which is output in the console "alert() is not supported in background windows; please use console.log instead." is clear. alert() is not supported in background scripts. If you want more information, you might check Bug 1203394 - alert() does not work in background scripts which is RESOLVED FIXED with this console output as the result.
    – Makyen
    Aug 15 '16 at 14:26










  • To be clear: Will you accept a substitute which works in both Firefox and Google Chrome which comes close to looking and acting like an alert()?
    – Makyen
    Aug 15 '16 at 14:28










  • Also to be clear: it is not acceptable to you to have as a solution that a content script be loaded to accomplish the alert(). This is not saying send a message to an already loaded content script, but actually loading one specifically to handle this issue. This is not an acceptable solution to you, correct?
    – Makyen
    Aug 15 '16 at 14:32










  • @Makyen Give it a shot.
    – AlJo
    Aug 15 '16 at 16:44






  • 1




    @Makyen, you're making rash unimaginative assumptions. If you can't answer the question as stated, don't let that bother you; just move along.
    – AlJo
    Aug 16 '16 at 2:52
















The way that you have worded this it sounds like you will accept no solution other than the actual alert() dialog, not even something that looks and feels like it. If so, then you are SOL. The text which is output in the console "alert() is not supported in background windows; please use console.log instead." is clear. alert() is not supported in background scripts. If you want more information, you might check Bug 1203394 - alert() does not work in background scripts which is RESOLVED FIXED with this console output as the result.
– Makyen
Aug 15 '16 at 14:26




The way that you have worded this it sounds like you will accept no solution other than the actual alert() dialog, not even something that looks and feels like it. If so, then you are SOL. The text which is output in the console "alert() is not supported in background windows; please use console.log instead." is clear. alert() is not supported in background scripts. If you want more information, you might check Bug 1203394 - alert() does not work in background scripts which is RESOLVED FIXED with this console output as the result.
– Makyen
Aug 15 '16 at 14:26












To be clear: Will you accept a substitute which works in both Firefox and Google Chrome which comes close to looking and acting like an alert()?
– Makyen
Aug 15 '16 at 14:28




To be clear: Will you accept a substitute which works in both Firefox and Google Chrome which comes close to looking and acting like an alert()?
– Makyen
Aug 15 '16 at 14:28












Also to be clear: it is not acceptable to you to have as a solution that a content script be loaded to accomplish the alert(). This is not saying send a message to an already loaded content script, but actually loading one specifically to handle this issue. This is not an acceptable solution to you, correct?
– Makyen
Aug 15 '16 at 14:32




Also to be clear: it is not acceptable to you to have as a solution that a content script be loaded to accomplish the alert(). This is not saying send a message to an already loaded content script, but actually loading one specifically to handle this issue. This is not an acceptable solution to you, correct?
– Makyen
Aug 15 '16 at 14:32












@Makyen Give it a shot.
– AlJo
Aug 15 '16 at 16:44




@Makyen Give it a shot.
– AlJo
Aug 15 '16 at 16:44




1




1




@Makyen, you're making rash unimaginative assumptions. If you can't answer the question as stated, don't let that bother you; just move along.
– AlJo
Aug 16 '16 at 2:52




@Makyen, you're making rash unimaginative assumptions. If you can't answer the question as stated, don't let that bother you; just move along.
– AlJo
Aug 16 '16 at 2:52












1 Answer
1






active

oldest

votes


















3














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});





share|improve this answer























  • this hack worked, thanks!
    – Lunulata
    Apr 29 '17 at 5:25






  • 3




    This hack does not work, when the active tab is e.g. an "about:" page, new tab and other similar situations, and that's precisely where I need to show an error message and suggestion how to work around the problem. Any other ideas?
    – gregko
    Oct 12 '17 at 18:29










  • Note that you need host permissions to inject into the current page. Thankfully, most of the time activeTab permission is sufficient. gregko's use case needs more work, however. An option would be to open a visible extension page for this in case the injection fails; clunky for sure.
    – Xan
    Nov 14 '18 at 13:25













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38950281%2fneed-workaround-for-calling-alert-from-background-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














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});





share|improve this answer























  • this hack worked, thanks!
    – Lunulata
    Apr 29 '17 at 5:25






  • 3




    This hack does not work, when the active tab is e.g. an "about:" page, new tab and other similar situations, and that's precisely where I need to show an error message and suggestion how to work around the problem. Any other ideas?
    – gregko
    Oct 12 '17 at 18:29










  • Note that you need host permissions to inject into the current page. Thankfully, most of the time activeTab permission is sufficient. gregko's use case needs more work, however. An option would be to open a visible extension page for this in case the injection fails; clunky for sure.
    – Xan
    Nov 14 '18 at 13:25


















3














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});





share|improve this answer























  • this hack worked, thanks!
    – Lunulata
    Apr 29 '17 at 5:25






  • 3




    This hack does not work, when the active tab is e.g. an "about:" page, new tab and other similar situations, and that's precisely where I need to show an error message and suggestion how to work around the problem. Any other ideas?
    – gregko
    Oct 12 '17 at 18:29










  • Note that you need host permissions to inject into the current page. Thankfully, most of the time activeTab permission is sufficient. gregko's use case needs more work, however. An option would be to open a visible extension page for this in case the injection fails; clunky for sure.
    – Xan
    Nov 14 '18 at 13:25
















3












3








3






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});





share|improve this answer














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});






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 9 '17 at 12:09









S.I.

1,87082641




1,87082641










answered Jan 9 '17 at 11:08









GrafZahl

312




312












  • this hack worked, thanks!
    – Lunulata
    Apr 29 '17 at 5:25






  • 3




    This hack does not work, when the active tab is e.g. an "about:" page, new tab and other similar situations, and that's precisely where I need to show an error message and suggestion how to work around the problem. Any other ideas?
    – gregko
    Oct 12 '17 at 18:29










  • Note that you need host permissions to inject into the current page. Thankfully, most of the time activeTab permission is sufficient. gregko's use case needs more work, however. An option would be to open a visible extension page for this in case the injection fails; clunky for sure.
    – Xan
    Nov 14 '18 at 13:25




















  • this hack worked, thanks!
    – Lunulata
    Apr 29 '17 at 5:25






  • 3




    This hack does not work, when the active tab is e.g. an "about:" page, new tab and other similar situations, and that's precisely where I need to show an error message and suggestion how to work around the problem. Any other ideas?
    – gregko
    Oct 12 '17 at 18:29










  • Note that you need host permissions to inject into the current page. Thankfully, most of the time activeTab permission is sufficient. gregko's use case needs more work, however. An option would be to open a visible extension page for this in case the injection fails; clunky for sure.
    – Xan
    Nov 14 '18 at 13:25


















this hack worked, thanks!
– Lunulata
Apr 29 '17 at 5:25




this hack worked, thanks!
– Lunulata
Apr 29 '17 at 5:25




3




3




This hack does not work, when the active tab is e.g. an "about:" page, new tab and other similar situations, and that's precisely where I need to show an error message and suggestion how to work around the problem. Any other ideas?
– gregko
Oct 12 '17 at 18:29




This hack does not work, when the active tab is e.g. an "about:" page, new tab and other similar situations, and that's precisely where I need to show an error message and suggestion how to work around the problem. Any other ideas?
– gregko
Oct 12 '17 at 18:29












Note that you need host permissions to inject into the current page. Thankfully, most of the time activeTab permission is sufficient. gregko's use case needs more work, however. An option would be to open a visible extension page for this in case the injection fails; clunky for sure.
– Xan
Nov 14 '18 at 13:25






Note that you need host permissions to inject into the current page. Thankfully, most of the time activeTab permission is sufficient. gregko's use case needs more work, however. An option would be to open a visible extension page for this in case the injection fails; clunky for sure.
– Xan
Nov 14 '18 at 13:25




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38950281%2fneed-workaround-for-calling-alert-from-background-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine