Skip to content

Commit

Permalink
fix: check if page has title element
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Oct 5, 2022
1 parent 1a8ee26 commit 44620cc
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/app-backend-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,18 +661,16 @@ function connectBridge () {

ctx.bridge.send(BridgeEvents.TO_FRONT_TITLE, { title: document.title })
// Watch page title
if (typeof MutationObserver !== 'undefined') {
const titleEl = document.querySelector('title')
if (titleEl && typeof MutationObserver !== 'undefined') {
if (pageTitleObserver) {
pageTitleObserver.disconnect()
}
pageTitleObserver = new MutationObserver((mutations) => {
const title = mutations[0].target as HTMLTitleElement
ctx.bridge.send(BridgeEvents.TO_FRONT_TITLE, { title: title.innerText })
})
pageTitleObserver.observe(
document.querySelector('title'),
{ subtree: true, characterData: true, childList: true },
)
pageTitleObserver.observe(titleEl, { subtree: true, characterData: true, childList: true })
}
}

Expand Down

1 comment on commit 44620cc

@cinderisles
Copy link

@cinderisles cinderisles commented on 44620cc Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix, just experienced this bug. devtools wouldnt load pinia. Adding a <title> tag to index.html fixed it

The error:

backend.js:2587 Uncaught (in promise) TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
    at connectBridge (backend.js:2587:23)
    at connect (backend.js:1993:3)

Please sign in to comment.