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

[ContentFeature] de-decouple build specific code from content-features #1545

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

dbajpeyi
Copy link
Contributor

@dbajpeyi dbajpeyi commented Mar 5, 2025

Asana Task/Github Issue:

Description

Testing Steps

Checklist

Please tick all that apply:

  • I have tested this change locally
  • I have tested this change locally in all supported browsers
  • This change will be visible to users
  • I have added automated tests that cover this change
  • I have ensured the change is gated by config
  • This change was covered by a ship review
  • This change was covered by a tech design
  • Any dependent config has been merged

Copy link

netlify bot commented Mar 5, 2025

Deploy Preview for content-scope-scripts ready!

Name Link
🔨 Latest commit 91e99dc
🔍 Latest deploy log https://app.netlify.com/sites/content-scope-scripts/deploys/67cad8e94515a1000813e202
😎 Deploy Preview https://deploy-preview-1545--content-scope-scripts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Mar 5, 2025

Temporary Branch Update

The temporary branch has been updated with the latest changes. Below are the details:

Please use the above install command to update to the latest version.

Copy link

github-actions bot commented Mar 5, 2025

[Beta] Generated file diff

Time updated: Fri, 07 Mar 2025 11:31:42 GMT

Android
    - android/autofillPasswordImport.js
  • android/brokerProtection.js
  • android/contentScope.js

File has changed

Chrome
    - chrome/inject.js

File has changed

Chrome-mv3
    - chrome-mv3/inject.js

File has changed

Firefox
    - firefox/inject.js

File has changed

Integration
    - integration/contentScope.js

File has changed

Windows
    - windows/contentScope.js

File has changed

Apple
    - dist/contentScope.js
  • dist/contentScopeIsolated.js

File has changed

@dbajpeyi dbajpeyi force-pushed the dbajpeyi/refactor/decouple-import-meta branch from f87255a to c5e86a4 Compare March 5, 2025 15:28
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/refactor/decouple-import-meta branch 4 times, most recently from 894cce5 to 512b303 Compare March 5, 2025 16:32
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/refactor/decouple-import-meta branch from 512b303 to e7e6721 Compare March 5, 2025 17:26
@@ -31,10 +30,14 @@ function initCode() {
debug: processedConfig.debug,
});

const importConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move this into content-scope-features to remove the need for it being in all files?

@@ -463,7 +463,7 @@ export class WebCompat extends ContentFeature {

mediaSessionFix() {
try {
if (window.navigator.mediaSession && import.meta.injectName !== 'integration') {
if (window.navigator.mediaSession && this.injectName !== 'integration') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be this.importConfig.injectName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a getter in the base class.

@dbajpeyi dbajpeyi changed the title (wip) refactor: move utility function to a separate class (wip) refactor: move utility function to a config class Mar 5, 2025
@@ -39,7 +37,7 @@ export function load(args) {
return;
}

const featureNames = typeof import.meta.injectName === 'string' ? platformSupport[import.meta.injectName] : [];
Copy link
Contributor

Choose a reason for hiding this comment

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

In the for loop below I think you'll need to pass in importConfig into the ContentFeature, probably to the constructor.

@dbajpeyi dbajpeyi force-pushed the dbajpeyi/refactor/decouple-import-meta branch from 917f4f8 to db3cdf8 Compare March 6, 2025 14:04
@dbajpeyi dbajpeyi changed the title (wip) refactor: move utility function to a config class [ContentFeature] de-decouple build specific code from logic Mar 6, 2025
this.#args = null;
constructor(featureName, importConfig) {
super(featureName);
this.args = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.args = null;
this.#args = null;

@dbajpeyi dbajpeyi force-pushed the dbajpeyi/refactor/decouple-import-meta branch 2 times, most recently from d309b19 to 85dfc98 Compare March 6, 2025 14:41
Comment on lines 48 to 49
const featureInstance = new ContentFeature(featureName, importConfig);
featureInstance.callLoad(args);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const featureInstance = new ContentFeature(featureName, importConfig);
featureInstance.callLoad(args);
const featureInstance = new ContentFeature(featureName, importConfig, args);
featureInstance.callLoad();

Later on:

featureInstance.callInit(args);

Copy link
Contributor

Choose a reason for hiding this comment

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

This change would allow us to move the initLoadArgs it super constructor.

@@ -54,7 +54,6 @@ function init() {
platform: {
name: 'extension'
},
trackerLookup: ${JSON.stringify(trackerLookup)},
site: ${JSON.stringify(siteObject)},
documentOriginIsTracker: ${documentOriginIsTracker},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
documentOriginIsTracker: ${documentOriginIsTracker},

@dbajpeyi dbajpeyi force-pushed the dbajpeyi/refactor/decouple-import-meta branch from 85dfc98 to 363da49 Compare March 6, 2025 15:03
Comment on lines 36 to 37
constructor(featureName, importConfig) {
super(featureName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
constructor(featureName, importConfig) {
super(featureName);
constructor(featureName, importConfig, args) {
super(featureName, args);

Comment on lines 36 to 46
initLoadArgs(loadArgs) {
const { bundledConfig, site, platform } = loadArgs;
this.#bundledConfig = bundledConfig;
this.#args = loadArgs;
// If we have a bundled config, treat it as a regular config
// This will be overriden by the remote config if it is available
if (this.#bundledConfig && this.#args) {
const enabledFeatures = computeEnabledFeatures(bundledConfig, site.domain, platform.version);
this.#args.featureSettings = parseFeatureSettings(bundledConfig, enabledFeatures);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

All this moves into the constructor.

/**
* @param {any} name
*/
constructor(name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
constructor(name) {
constructor(name, args) {

init(args) {}

callInit(args) {
const mark = this.monitor.mark(this.name + 'CallInit');
this.#args = args;
this.args = args;
Copy link
Contributor

Choose a reason for hiding this comment

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

This becomes a method called setArgs. That we call from the constructor and callInit. We remove these two lines from callLoad.

}
this.#trackerLookup = args.trackerLookup;
this.#documentOriginIsTracker = args.documentOriginIsTracker;
this.initLoadArgs(args);
Copy link
Contributor

Choose a reason for hiding this comment

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

This initLoadArgs becomes part of the constructor (just calling super with the args).

}
this.#trackerLookup = args.trackerLookup;
this.#documentOriginIsTracker = args.documentOriginIsTracker;
this.initLoadArgs(args);
this.load(args);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.load(args);
this.load(this.#args);

Copy link
Contributor

Choose a reason for hiding this comment

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

(this passing in is legacy btw, I think there's very few uses of it).

@dbajpeyi dbajpeyi force-pushed the dbajpeyi/refactor/decouple-import-meta branch 3 times, most recently from 3ac99d4 to 3239109 Compare March 7, 2025 10:33
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/refactor/decouple-import-meta branch from 83024d3 to 2562c00 Compare March 7, 2025 10:44
@dbajpeyi dbajpeyi changed the title [ContentFeature] de-decouple build specific code from logic [ContentFeature] de-decouple build specific code from content-features Mar 7, 2025
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.

2 participants