Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6649: Exclude navigation events that should not trigger page updates #7178

Merged
merged 8 commits into from
Dec 22, 2023

Conversation

fregante
Copy link
Contributor

What does this PR do?

Demo

date

Checklist

  • Add tests
  • New files added to src/tsconfig.strictNullChecks.json (if possible)
  • Designate a primary reviewer: @grahamlangford

Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (2ec84a9) 71.31% compared to head (faf634b) 71.29%.

Files Patch % Lines
src/contentScript/lifecycle.ts 33.33% 12 Missing ⚠️
src/background/navigation.ts 0.00% 5 Missing ⚠️
src/background/background.ts 0.00% 1 Missing ⚠️
src/contentScript/contentScriptCore.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7178      +/-   ##
==========================================
- Coverage   71.31%   71.29%   -0.02%     
==========================================
  Files        1214     1214              
  Lines       37780    37782       +2     
  Branches     7086     7089       +3     
==========================================
- Hits        26941    26937       -4     
- Misses      10839    10845       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -65,8 +65,7 @@ export async function init(): Promise<void> {
initTelemetry();
initToaster();

await handleNavigate();
initNavigation();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

initNavigation should deal with this directly

Kinda suggested here: #7030 (comment)

contentScriptState: getTargetState(target),
canInject: canInjectTab(target),
// PixieBrix has some additional constraints on which tabs can be accessed (i.e., only http/https)
canAccessTab: canAccessTab(target),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of waiting for each, sequential request, this triggers them in parallel and logs the navigation immediately, instead of possibly out of order.

Promises are still expandable in the console.

}

browser.webNavigation.onHistoryStateUpdated.addListener(
debouncedTraceNavigation,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this to use debouncing too

*/
const _frameHref = new Map<number, string>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The content script runs in a single frame. The frameId is always the same.

// extension background page.
thisTarget = await getThisFrame();
} catch (error: unknown) {
console.debug("Ignoring handleNavigate because getThisFrame failed", error);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If that happens, that's a setup error. We fixed this specific issue in:

Also in MV3 iframes cannot load in the background page at all.

_frameHref.set(thisTarget.frameId, href);

console.debug("Handling navigation to %s", href, thisTarget);
console.debug("handleNavigate:Handling navigation to %s", href, thisTarget);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Easy log filtering when all the logs have the same prefix

date

leading: true,
trailing: true,
maxWait: 1000,
}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied the debouncing and its comment from the original background listeners.

// Let the content script know about navigation from the history API. Required for handling SPA navigation
browser.webNavigation.onHistoryStateUpdated.addListener(onNavigation);
async function initNavigation(): Promise<void> {
if (!(await flagOn("navigation-trace"))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where is this flag defined? This is the only mention in both the extension and the app. I thought this was connected to the "performanceTracing" skunkworks toggle but it's not.

Untested for this reason

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's defined and managed in the Django Admin for App.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's defined and managed in the Django Admin for App.

Correct, it comes in via the /api/me/ API endpoint

Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@fregante fregante merged commit d22895a into main Dec 22, 2023
17 checks passed
@fregante fregante deleted the F/feature/safe-navigate branch December 22, 2023 17:18
@grahamlangford grahamlangford added this to the 1.8.6 milestone Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants