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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3510: mark content script nonce on DOM #3718

Merged
merged 2 commits into from Jun 15, 2022

Conversation

twschiller
Copy link
Contributor

What does this PR do?

Checklist

  • 馃槥 Add tests
  • Designate a primary reviewer: @fregante

@twschiller twschiller added this to the 1.7.0 milestone Jun 15, 2022
@twschiller twschiller requested a review from fregante June 15, 2022 01:55
@twschiller twschiller self-assigned this Jun 15, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2022

Codecov Report

Merging #3718 (de6a2a8) into main (80170b1) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #3718      +/-   ##
==========================================
- Coverage   45.99%   45.99%   -0.01%     
==========================================
  Files         829      829              
  Lines       24741    24746       +5     
  Branches     5188     5189       +1     
==========================================
+ Hits        11380    11381       +1     
- Misses      12435    12439       +4     
  Partials      926      926              
Impacted Files Coverage 螖
src/contentScript/contentScript.ts 0.00% <0.00%> (酶)
src/pageEditor/hooks/useExtensionTrace.ts 80.00% <0.00%> (+3.33%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 80170b1...de6a2a8. Read the comment docs.

@twschiller twschiller merged commit c2fc672 into main Jun 15, 2022
@twschiller twschiller deleted the feature/3510-duplicate-content-script branch June 15, 2022 02:03
Copy link
Collaborator

@fregante fregante left a comment

Choose a reason for hiding this comment

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

Did you confirm that Symbol was the problem? It would still be surprising to me.

In that case, LGTM except a couple of notes

const PIXIEBRIX_SYMBOL = Symbol.for("pixiebrix-content-script");
const uuid = uuidv4();
// Should set attribute as early as possible
document.documentElement.setAttribute(PIXIEBRIX_CONTENT_SCRIPT_NONCE, uuid);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Keep in mind that imports are executed before this code, so placing it up here doesn't make any difference.

In a future PR, I'd suggest to:

  1. Move all the code except the duplication checker out to contentScript2.js (example)
  2. Keep only the logic if not yet loaded, import(contentScript2.js) here

This guarantees that no code is ever executed twice. It also makes the check faster since the new contentScript.js would be very light.

@@ -39,9 +45,6 @@ import { initToaster } from "@/utils/notify";
import { isConnectionError } from "@/errors/errorHelpers";
import { showConnectionLost } from "@/contentScript/connection";

const PIXIEBRIX_SYMBOL = Symbol.for("pixiebrix-content-script");
const uuid = uuidv4();

registerMessenger();
registerExternalMessenger();
registerBuiltinBlocks();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should all of these also be moved inside init?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The content script is injected twice (editor open, click browser action)
3 participants