rewrite page.title as a function

This commit is contained in:
CanadaHonk 2023-01-24 08:29:17 +00:00
parent 9ea7835bb6
commit 8e36c19f11
2 changed files with 12 additions and 4 deletions

10
gluon.d.ts vendored
View File

@ -11,8 +11,14 @@ type PageApi = {
/** Promise for waiting until the page has loaded. */ /** Promise for waiting until the page has loaded. */
loaded: Promise<void>, loaded: Promise<void>,
/** Get or set the title of the page (async) */ /**
title: Promise<string> * Get or set the title of the page.
* Use no arguments to get the title, or provide a string to set it.
*/
title: (
/** Set the page title to a new title. */
newTitle: string
) => Promise<string>
}; };
type IPCStoreApi = { type IPCStoreApi = {

View File

@ -99,8 +99,10 @@ export default async (CDP, proc, injectionType = 'browser', { browserName, brows
eval: evalInWindow, eval: evalInWindow,
loaded: pageLoadPromise, loaded: pageLoadPromise,
get title() { return evalInWindow('document.title'); }, title: val => {
set title(val) { return evalInWindow(`document.title = \`${val}\``); } if (!val) return evalInWindow('document.title');
return evalInWindow(`document.title = \`${val}\``);
}
}, },
ipc: IPC, ipc: IPC,