Skip to content

Commit 55db1b4

Browse files
committed
Fix: use window object directly
I saw an error: Uncaught (in promise) SecurityError: Failed to read a named property 'document' from 'Window': Blocked a frame with origin "lsp://logseq.io" from accessing a cross-origin frame. at un.No (index-DgzxW5Zo.js:12:50464) at un.ready (index-DgzxW5Zo.js:12:44434)
1 parent 9939a3f commit 55db1b4

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function recordPositionForBlock(uuid: string, mode: BlockMode = 'edit') {
7272
const debouncedRecordPosition = debounce(recordPositionForBlock, 500)
7373

7474
function startBlockFocusTracking() {
75-
const editorDoc = top?.document
75+
const editorDoc = window?.document
7676
if (!editorDoc) return
7777

7878
editorDoc.addEventListener('focusout', (e) => {
@@ -86,7 +86,7 @@ function startBlockFocusTracking() {
8686
}
8787

8888
function startBlockSelectionTracking() {
89-
const appContainer = top?.document.getElementById('app-container')
89+
const appContainer = window.document.getElementById('app-container')
9090
if (!appContainer) return
9191

9292
const observer = new MutationObserver((mutations) => {
@@ -112,7 +112,7 @@ function startBlockSelectionTracking() {
112112

113113
async function scrollToAndSelectBlock(blockUuid: string) {
114114
const id = 'block-content-' + blockUuid
115-
const elem = top?.document.getElementById(id)
115+
const elem = window.document.getElementById(id)
116116
if (elem) {
117117
elem.scrollIntoView({ behavior: 'smooth' })
118118
await logseq.Editor.selectBlock(blockUuid)

0 commit comments

Comments
 (0)