Skip to content

Commit

Permalink
perf: Perform the first scan for landmarks sooner (#307)
Browse files Browse the repository at this point in the history
Closes #306
  • Loading branch information
matatk authored Mar 25, 2019
1 parent a111cee commit 4992396
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/code/_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function shouldRefreshLandmarkss(mutations) {
return false
}

function setUpMutationObserver() {
function createMutationObserver() {
observer = new MutationObserver(function(mutations) {
msr.incrementTotalMutations()

Expand All @@ -214,8 +214,6 @@ function setUpMutationObserver() {

msr.sendMutationUpdate()
})

observeMutationObserver()
}

function observeMutationObserver() {
Expand All @@ -229,6 +227,12 @@ function observeMutationObserver() {
})
}

function observeMutationObserverAndFindLandmarks() {
observeMutationObserver()
findLandmarksAndUpdateExtension()
msr.sendMutationUpdate()
}

function reflectPageVisibility() {
if (document.hidden) {
if (observerReconnectionTimer) {
Expand All @@ -238,9 +242,7 @@ function reflectPageVisibility() {
observer.disconnect()
} else {
observerReconnectionTimer = setTimeout(function() {
observeMutationObserver()
findLandmarksAndUpdateExtension()
msr.sendMutationUpdate()
observeMutationObserverAndFindLandmarks()
observerReconnectionTimer = null
}, observerReconnectionGrace)
}
Expand All @@ -260,8 +262,8 @@ function bootstrap() {

// At the start, the ElementFocuser is always managing borders
browser.runtime.sendMessage({ name: 'toggle-state-is', data: 'selected' })
setUpMutationObserver()
reflectPageVisibility()
createMutationObserver()
observeMutationObserverAndFindLandmarks()
document.addEventListener('visibilitychange', reflectPageVisibility, false)
browser.runtime.sendMessage({ name: 'get-devtools-state' })
}
Expand Down

0 comments on commit 4992396

Please sign in to comment.