File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ function handleExternalScript() {
1111 const newScript = document . createElement ( 'script' ) ;
1212
1313 Array . from ( script . attributes ) . forEach ( attribute => {
14- newScript [ attribute . name ] = attribute . value ;
14+ newScript . setAttribute ( attribute . name , attribute . value ) ;
1515 } ) ;
1616
1717 script . before ( newScript ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,47 @@ import { waitForFunction } from '../helpers/wait-for.js';
33import { test , expect } from './fixtures/docsify-init-fixture.js' ;
44
55test . describe ( 'Plugins' , ( ) => {
6+ test ( 'external scripts retain their HTML attributes when executed' , async ( {
7+ page,
8+ } ) => {
9+ const pageErrors = [ ] ;
10+ page . on ( 'pageerror' , error => pageErrors . push ( error . message ) ) ;
11+ await docsifyInit ( {
12+ markdown : {
13+ homepage : `
14+ # External script
15+
16+ <script src="/widget.js" data-message="hello" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
17+ ` ,
18+ } ,
19+ routes : {
20+ '/widget.js' : `
21+ const script = document.currentScript;
22+ window.widgetAttributes = {
23+ message: script.dataset.message,
24+ crossOrigin: script.crossOrigin,
25+ referrerPolicy: script.referrerPolicy,
26+ };
27+ ` ,
28+ } ,
29+ scriptURLs : [ '/dist/plugins/external-script.js' ] ,
30+ } ) ;
31+
32+ await expect
33+ . poll ( async ( ) => ( {
34+ attributes : await page . evaluate ( ( ) => window . widgetAttributes ) ,
35+ errors : pageErrors ,
36+ } ) )
37+ . toEqual ( {
38+ attributes : {
39+ message : 'hello' ,
40+ crossOrigin : 'anonymous' ,
41+ referrerPolicy : 'no-referrer' ,
42+ } ,
43+ errors : [ ] ,
44+ } ) ;
45+ } ) ;
46+
647 test ( 'Hook order' , async ( { page } ) => {
748 const consoleMsgs = [ ] ;
849 const expectedMsgs = [
You can’t perform that action at this time.
0 commit comments