{
let win = await api.windows.create({
url,
focused: true,
width: 800,
height: 600
});
const close = async () => {
if (win) {
const id = win.id;
win = null;
await api.windows.remove(id);
}
};
invalidation.then(close);
try {
const windowId = win.id;
const tabId = win.tabs[0].id;
const { status, result, error } = await api.custom.injectScript(
{ tabId },
{
func: extractContentFromWebdriverIO.toString(),
args: []
}
);
if (status === "error") {
throw new Error(JSON.stringify(error));
}
return htl.html`<ul>${result.map(
({ title, description }) =>
htl.html`<li><strong>${title}</strong> ${description}</li>`
)}</ul>`;
} catch (error) {
console.error(error);
return htl.html`<div>ERROR! ${JSON.stringify(error.message)}<div>`;
} finally {
await close();
}
}