Skip to content

fix(external-script): preserve HTML attributes - #2819

Merged
sy-records merged 2 commits into
docsifyjs:developfrom
xu91102:fix/external-script-attributes
Oct 21, 2026
Merged

sy-records merged 2 commits into
docsifyjs:developfrom
xu91102:fix/external-script-attributes

Conversation

@xu91102

@xu91102 xu91102 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Summary

External scripts recreated by the external-script plugin lose HTML attributes such as data-message, crossorigin, and referrerpolicy. Assigning newScript[attribute.name] creates unrelated JavaScript properties for names that do not match DOM properties, so widgets lose configuration and browser request settings.

Copy attributes with setAttribute(). The browser regression executes a local script and reads document.currentScript.dataset, crossOrigin, and referrerPolicy from the actual replacement element.

Example: <script src="/widget.js" data-message="hello" crossorigin="anonymous" referrerpolicy="no-referrer"></script> now retains all three settings when executed by the plugin.

Related issue, if any:

Reproduced on develop at d823dbe51c1b2dea4c2091e2b952ded0d1e16616; no matching open fix found.

What kind of change does this PR introduce?

  • Bugfix

For any code change,

  • Related documentation has been updated, if needed (no new configuration)
  • Related tests have been added or updated

Does this PR introduce a breaking change?

  • No

Validation

  • Before the fix, the script ran without page errors but received undefined, null, and an empty string instead of the configured attribute values.
  • npm run test:e2e:chromium -- test/e2e/plugins.test.js --workers=1 --reporter=line: 9 tests passed, including the regression.
  • npm run test:jest -- --runInBand: 128 tests and 46 snapshots passed.
  • npm run build, npm run lint, npm run typecheck, and git diff --check: passed.
  • Independent read-only review: no required changes.

Browser coverage: Chromium via Playwright; Firefox, WebKit, and unrelated E2E suites were not run locally.

Developed with assistance from OpenAI Codex; regression and fix validated locally.

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Docsify Team on Vercel.

A member of the Team first needs to authorize it.

@sy-records
sy-records force-pushed the fix/external-script-attributes branch from de19ed0 to 9849872 Compare October 16, 2026 03:59
@trusktr

trusktr commented Oct 21, 2026

Copy link
Copy Markdown
Member

@sy-records what happened to the original author? I'm confused:

image image image
@sy-records

sy-records commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Maybe it's using Ai, but the configuration is wrong.

My commit is because of rebase.

@sy-records
sy-records merged commit 3d82b26 into docsifyjs:develop Oct 21, 2026
6 of 7 checks passed
@sy-records sy-records mentioned this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants