@@ -61,26 +61,35 @@ function findContainerWithExecute(container: ElementBase): WebdriverIO.Browser {
6161}
6262
6363async function injectDOMTestingLibrary ( container : ElementBase ) {
64- const containerWithExecute = findContainerWithExecute ( container ) ;
65- const shouldInjectDTL = await containerWithExecute . execute ( function ( ) {
64+ const browser = findContainerWithExecute ( container ) ;
65+ const shouldInjectDTL = await browser . execute ( function ( ) {
6666 return ! window . TestingLibraryDom ;
6767 } ) ;
6868
6969 if ( shouldInjectDTL ) {
70- await containerWithExecute . execute ( function ( library ) {
71- // add DOM Testing Library to page as a script tag to support Firefox
70+ await browser . execute ( function ( library ) {
7271 if ( navigator . userAgent . indexOf ( "Firefox" ) !== - 1 ) {
73- const script = window . document . createElement ( "script" ) ;
74- script . textContent = library ;
75- window . document . head . append ( script ) ;
76- window . eval ( library ) ;
72+ try {
73+ // Inject via inline-script
74+ const script = window . document . createElement ( "script" ) ;
75+ script . textContent = library ;
76+ window . document . head . append ( script ) ;
77+ if ( ! window . TestingLibraryDom ) {
78+ // Inject via eval
79+ window . eval ( library ) ;
80+ }
81+ } catch ( error ) {
82+ throw new Error (
83+ `The DOM Testing Library cannot be injected on certain domains, particularly "${ window . location . host } ", due to restrictions imposed by the Content-Security-Policy (CSP) header.` ,
84+ ) ;
85+ }
7786 } else {
7887 eval ( library ) ;
7988 }
8089 } , DOM_TESTING_LIBRARY_UMD ) ;
8190 }
8291
83- await containerWithExecute . execute ( function ( config : Partial < Config > ) {
92+ await browser . execute ( function ( config : Partial < Config > ) {
8493 window . TestingLibraryDom . configure ( config ) ;
8594 } , _config ) ;
8695}
@@ -109,7 +118,6 @@ function serializeArg(arg: QueryArg): SerializedArg {
109118type SerializedQueryResult = { selector : string } [ ] | string | { selector : string } | null ;
110119
111120async function executeQuery ( query : QueryName , container : HTMLElement , ...args : SerializedArg [ ] ) {
112- // const done = args.pop() as unknown as (result: SerializedQueryResult) => void;
113121 return new Promise ( ( done : ( result : SerializedQueryResult ) => void ) => {
114122 function deserializeObject ( object : SerializedObject ) {
115123 return Object . entries ( object )
@@ -154,7 +162,7 @@ async function executeQuery(query: QueryName, container: HTMLElement, ...args: S
154162 }
155163
156164 function makeSelectorResult ( element : HTMLElement ) : { selector : string } {
157- const elementIdAttributeName = "data-wdio-testing-lib -element-id" ;
165+ const elementIdAttributeName = "data-testplane -element-id" ;
158166 let elementId = element . getAttribute ( elementIdAttributeName ) ;
159167
160168 // if id doesn't already exist create one and add it to element
0 commit comments