A small module to open a window dialog with features in Add-on SDK. It's also possible attach content scripts to dialog with the document loaded.
const dialog = require('./dialog');
dialog.open({
// both `foo.html` and `index.js` are supposed to
// be in add-on's `data` folder
url: './foo.html',
contentScriptFile: './index.js',
features: {
width: 320,
height: 200
}
}).then(worker => {
// do something with worker, e.g.
worker.port.on('title', console.log);
});
open
function returns a promise resolved once the document is ready, passing
the worker
attached, if any contentScript*
was declared, or null
.
It's possible modify the window
object from the document's script itself, like
any regular web page, or if a worker
is returned, is possible access to
worker.tab
and worker.tab.window.
For example, this code will close the window
opened, after two seconds.
const dialog = require('./dialog');
const { setTimeout } = require('sdk/timers');
dialog.open({
url: './foo.html',
contentScriptFile: './index.js',
features: {
width: 320,
height: 200
}
}).then(worker => {
setTimeout(() => worker.tab.close(), 2000);
});