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

Improve logging around contentScript loading/deduplication code #5025

Merged
merged 8 commits into from
Jan 18, 2023

Conversation

fregante
Copy link
Contributor

@fregante fregante commented Jan 16, 2023

I'm sending this PR to test out this new base in preparation for further fixes related to the injection of the content scripts. Here I think the only behavior change is:

Related

Not included / not fixed

Tasks

  • Test the extension, especially around pixiebrix.com and overlapping permissions like *.example.com and *://*/* together

@codecov
Copy link

codecov bot commented Jan 16, 2023

Codecov Report

Merging #5025 (7ef6114) into main (5424cfa) will increase coverage by 0.00%.
The diff coverage is 0.00%.

❗ Current head 7ef6114 differs from pull request most recent head 6dd5e62. Consider uploading reports for the commit 6dd5e62 to get more accurate results

@@           Coverage Diff           @@
##             main    #5025   +/-   ##
=======================================
  Coverage   59.67%   59.68%           
=======================================
  Files         968      968           
  Lines       29261    29258    -3     
  Branches     5599     5598    -1     
=======================================
  Hits        17462    17462           
+ Misses      11799    11796    -3     
Impacted Files Coverage Δ
src/background/browserAction.ts 0.00% <ø> (ø)
src/contentScript/contentScript.ts 0.00% <0.00%> (ø)
src/contentScript/contentScriptCore.ts 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

);
return;
}

if (isReadyInThisDocument()) {
console.warn(
"contentScript: injecting again because the previous context was invalidated"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was no longer reached because at the end of initContentScript we're already marking the document as not ready

@@ -30,22 +29,17 @@ import { onContextInvalidated } from "@/errors/contextInvalidated";

// See note in `@/contentScript/ready.ts` for further details about the lifecycle of content scripts
async function initContentScript() {
const context = top === self ? "" : `in frame ${location.href}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before

Without this piece of information, it seems that there are multiple injections in the same page:

Screenshot 3

After

This makes it clear that there are multiple frames. I'm only logging this piece of information one to avoid too much noise. The console already allows filtering by context, should you wish to debug it further.

Screenshot 4

@@ -58,7 +52,7 @@ async function initContentScript() {
void logPromiseDuration("contentScript: imported", contentScript);

const { init } = await contentScript;
await init(uuid);
await logPromiseDuration("contentScript: ready", init());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case of duplicate injection, the previous setup was logging "ready" after an error. Moving the logging fixes it.

Screenshot 5

@fregante fregante marked this pull request as ready for review January 17, 2023 08:15
@fregante
Copy link
Contributor Author

@twschiller ready for merge. No change of behavior was seen

@fregante fregante added the do not merge Merging of this PR is blocked by another one label Jan 17, 2023
@fregante fregante removed the do not merge Merging of this PR is blocked by another one label Jan 17, 2023
@twschiller
Copy link
Contributor

@fregante I reviewed/approved #4984 instead

@fregante
Copy link
Contributor Author

This still contains additional code/logging improvements and can be merged separately. The only overlap is the dependency itself

@twschiller twschiller added this to the 1.7.18 milestone Jan 18, 2023
@twschiller
Copy link
Contributor

@fregante you'll need to resolve the merge conflicts

@fregante fregante changed the title Update webext-dynamic-content-scripts Improve logging around contentScript loading/deduplication code Jan 18, 2023
@fregante fregante enabled auto-merge (squash) January 18, 2023 16:34
@fregante fregante merged commit e202639 into main Jan 18, 2023
@fregante fregante deleted the F/bug/update-dynamic-cs branch January 18, 2023 16:50
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.

2 participants