You can define additional browsers by declaring them in a file called
qtap.config.js
in the current directory, or any other importable
JavaScript file passed specified via the qtap --config
option.
// ESM
export default {
browsers: {
foo,
bar,
quux,
}
}
// CommonJS
module.exports = {
browsers: {
foo,
bar,
quux,
}
}
Browser plugins are defined by implementing a launch function with the following signature. Launchers are either an async function, or a function that returns a Promise.
/**
* @param {string} clientId Identify the given client, e.g. "client_42".
* @param {string} url HTTP(S) URL that the browser should navigate to.
* @param {AbortSignal} signal
* @param {qtap-Logger} logger
* @return {Promise}
*/
launch(clientId, url, signal, logger);
The browser is then registered in one of three ways:
object
: an object withlaunch
method.function
: a function that returns such object.class
: a class that implement alaunch
method.
const browserObj = {
async launch(clientId, url, signal, logger) {
// open browser
// navigate to url
// stop browser when signal sends 'abort' event.
// return/resolve once the process ends.
// throw/reject if the process fails or can't start.
}
};
export default {
browsers: {
foo: browserObj
}
}
function browserFn(logger) {
// ..
return {
async launch(url, signal, logger, clientId) {
// ...
}
};
};
export default {
browsers: {
foo: browserFn
}
}
class MyBrowser {
constructor (logger) {
// ...
}
async launch(url, signal, logger, clientId) {
// ...
}
async cleanupOnce() {
// Optional
}
};
export default {
browsers: {
foo: MyBrowser
}
}