From 8e36c19f115e86680fda76a0c788d4e44d07f630 Mon Sep 17 00:00:00 2001 From: CanadaHonk Date: Tue, 24 Jan 2023 08:29:17 +0000 Subject: [PATCH] rewrite page.title as a function --- gluon.d.ts | 10 ++++++++-- src/launcher/inject.js | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gluon.d.ts b/gluon.d.ts index dedcf93..4debfb5 100644 --- a/gluon.d.ts +++ b/gluon.d.ts @@ -11,8 +11,14 @@ type PageApi = { /** Promise for waiting until the page has loaded. */ loaded: Promise, - /** Get or set the title of the page (async) */ - title: Promise + /** + * 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 }; type IPCStoreApi = { diff --git a/src/launcher/inject.js b/src/launcher/inject.js index e13c942..c27975e 100644 --- a/src/launcher/inject.js +++ b/src/launcher/inject.js @@ -99,8 +99,10 @@ export default async (CDP, proc, injectionType = 'browser', { browserName, brows eval: evalInWindow, loaded: pageLoadPromise, - get title() { return evalInWindow('document.title'); }, - set title(val) { return evalInWindow(`document.title = \`${val}\``); } + title: val => { + if (!val) return evalInWindow('document.title'); + return evalInWindow(`document.title = \`${val}\``); + } }, ipc: IPC,