in "onHeadersReceived" listener

(Emile362) #1

Hello everyone, this topic come next to Downloads Api
I have another problem…
I try to call ““an extension_url”)” in a function called by a fucntion called by “browser.webRequest.onHeadersReceived.addListener()”…
I presume it is forbidden for security reasons…
I explain if you have not read my first topic…
I intercept all webrequests and filter them with “browser.webRequest.onHeadersReceived.addListener” (i cant use onResponseStarted because i need to cancel response easily before she start…)
the listener call a function which is a window in html for user to let him choose to cancel or not the request and make others things…
if someone has a solution…
maybe i could call a dialog window which is not an url but a sort of dialog window of firefox… but i dont know if it is possible ?
Sorry for my english again… i must train…

(Michel Gutierrez) #2

The API is probably what you are looking for. In particular, This is the way to open dialog-like windows from within the add-on background.

Please, do not apologize for your English. First it is good. Second, if you make the effort to write in English, people will make the effort to understand.

(Emile362) #3

Thanks a lot, it’s work fine but…
With the windows.create, i cannot close my windows with "window.close"
With “” i can easily close my window with “window.close” but like doesnt work on a function called by “onHeadersReceived”… Im in a cleft… and i cannot no more close my window with an internal script of the html page loaded in the window because firefox say that it is forbidden to close a page not opened by a script(technically, the page has been opened by a script… i suppose it can be only closed by the same script…)…
My aim is to have a button on the window created to validate parameters and close automatically when this one is clicked… I search a solution on the documentation since yesterday… but all my trials are unsucceseful…

(Michel Gutierrez) #4

When calling, did you try to set parameter allowScriptsToClose to true ?

(Emile362) #5

Of course, but i have the same error that tell me that closing script not opened by script is forbidden here is my code :

var PageValidation = {
type: “detached_panel”,
url: “/validation/validation.html”,
width: 400,
height: 350,
allowScriptsToClose: true

// rows of code

here i try window.close(), windows.remove() with many different syntaxes

and it doesnt work…

and else when i call window.close() in a function called by a listener on the script of “validation.html” i get the error that tell me the window cannot be closed by script…

if someone has a working example… i try to observe the correct syntaxe but whatever i write… it doesnt work

(Michel Gutierrez) #6

You should be able to call from the same script you created it:

var windowId;{
  // window details
  windowId =;

then later:;

And if the code running in your window is part of your extension, you should also be able to do:;


(Emile362) #7

Thanks a lot Michel… everything works fine now…
My mistake was on ID retrieval… for multiple instances of windows…(i hate asynchronous developing :sweat_smile: ).
Anyway, thanks for your help, my extension is almost ready now.