Skip to content

Inherit crossorigin on the injected web-vitals script#195

Open
arpitjain099 wants to merge 1 commit into
digital-analytics-program:developfrom
arpitjain099:chore/web-vitals-inherit-crossorigin
Open

Inherit crossorigin on the injected web-vitals script#195
arpitjain099 wants to merge 1 commit into
digital-analytics-program:developfrom
arpitjain099:chore/web-vitals-inherit-crossorigin

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #167.

On a page that sets Cross-Origin-Embedder-Policy: require-corp, the DAP tag can be given a crossorigin attribute so its response satisfies the policy. That works for Universal-Federated-Analytics-Min.js itself, but the web-vitals script that the analytics code injects dynamically (web-vitals.attribution.iife.js) never received the attribute, so it was blocked from loading (screenshot in the issue).

This reads the crossorigin value from the DAP script tag (#_fed_an_ua_tag, already referenced elsewhere in the file) and applies it to the injected web-vitals <script> element when present. When the page does not set crossorigin, nothing changes.

Universal-Federated-Analytics.js is the source; I regenerated Universal-Federated-Analytics-Min.js (and its map) with the repo's own npm run minify (terser + terser.config.json). Both files pass node --check.

On pages that set Cross-Origin-Embedder-Policy: require-corp, the DAP tag
can carry a crossorigin attribute so its response satisfies the policy. The
dynamically injected web-vitals script never received that attribute, so it
was blocked from loading on such pages.

Read the crossorigin value from the DAP script tag (#_fed_an_ua_tag) and
apply it to the web-vitals script element when present. Regenerated the
minified bundle with the project's terser config.

Fixes digital-analytics-program#167

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.

web-vitals.attribution.iife.js does not inherit crossorigin attribute from parent Universal-Federated-Analytics-Min.js script

1 participant