Hello everyone, this topic come next to Downloads Api
I have another problem…
I try to call “window.open(“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…
The browser.windows
API is probably what you are looking for. In particular, browser.windows.create()
. 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.
Thanks a lot, it’s work fine but…
With the windows.create, i cannot close my windows with "window.close"
With “window.open” i can easily close my window with “window.close” but like window.open() 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…
When calling browser.windows.create()
, did you try to set parameter allowScriptsToClose
to true
?
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
};
browser.windows.create(PageValidation);
// 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
You should be able to call browser.windows.remove()
from the same script you created it:
var windowId;
browser.windows.create({
// window details
}).then((window)=>{
windowId = window.id;
});
then later:
browser.windows.remove(windowId);
And if the code running in your window is part of your extension, you should also be able to do:
browser.windows.remove(browser.windows.WINDOW_ID_CURRENT);
or:
browser.windows.getCurrent()
.then((window)=>{
browser.windows.remove(window.id);
})
Thanks a lot Michel… everything works fine now…
My mistake was on ID retrieval… for multiple instances of windows…(i hate asynchronous developing ).
Anyway, thanks for your help, my extension is almost ready now.