Skip to content

Commit

Permalink
feat(browser-extension): skip ready state check in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
wanhose committed Sep 29, 2023
1 parent 8d79e35 commit c8d1f92
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/browser-extension/src/scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,18 @@ function readingTime() {
/**
* @async
* @description Sets up everything
* @param {boolean} skipReadyStateHack
*/

async function runSetup() {
async function runSetup(skipReadyStateHack) {
state = (await dispatch({ hostname, type: 'GET_HOSTNAME_STATE' })) ?? state;
dispatch({ type: 'ENABLE_POPUP' });

if (state.enabled) {
data = await dispatch({ hostname, type: 'GET_DATA' });

// 2023-06-13: hack to force clean when data request takes too long and there are no changes later
if (document.readyState === 'complete') {
if (document.readyState === 'complete' && !skipReadyStateHack) {
window.dispatchEvent(new Event('run'));
}

Expand All @@ -239,14 +240,16 @@ const observer = new MutationObserver((mutations) => {
});

/**
* @async
* @description Runs setup if the page wasn't focused yet
* @listens window#focus
* @returns {void}
*/

window.addEventListener('focus', () => {
window.addEventListener('focus', async () => {
if (!data) {
runSetup();
await runSetup(true);
forceClean(document.body);
}
});

Expand Down

0 comments on commit c8d1f92

Please sign in to comment.