@@ -192,14 +192,14 @@ function addLoopProtect(sketchDoc) {
192192 } ) ;
193193}
194194
195- function injectLocalFiles ( files , htmlFile ) {
195+ function injectLocalFiles ( files , htmlFile , basePath ) {
196196 let scriptOffs = [ ] ;
197197 const resolvedFiles = resolveJSAndCSSLinks ( files ) ;
198198 const parser = new DOMParser ( ) ;
199199 const sketchDoc = parser . parseFromString ( htmlFile . content , 'text/html' ) ;
200200
201201 const base = sketchDoc . createElement ( 'base' ) ;
202- base . href = `${ window . location . href } /` ;
202+ base . href = `${ basePath } /` ;
203203 sketchDoc . head . appendChild ( base ) ;
204204
205205 resolvePathsForElementsWithAttribute ( 'src' , sketchDoc , resolvedFiles ) ;
@@ -230,7 +230,7 @@ function getHtmlFile(files) {
230230 return files . filter ( ( file ) => file . name . match ( / .* \. h t m l $ / i) ) [ 0 ] ;
231231}
232232
233- function EmbedFrame ( { files, isPlaying } ) {
233+ function EmbedFrame ( { files, isPlaying, basePath } ) {
234234 const iframe = useRef ( ) ;
235235 const htmlFile = useMemo ( ( ) => getHtmlFile ( files ) , [ files ] ) ;
236236
@@ -247,7 +247,7 @@ function EmbedFrame({ files, isPlaying }) {
247247 function renderSketch ( ) {
248248 const doc = iframe . current ;
249249 if ( isPlaying ) {
250- const htmlDoc = injectLocalFiles ( files , htmlFile ) ;
250+ const htmlDoc = injectLocalFiles ( files , htmlFile , basePath ) ;
251251 srcDoc . set ( doc , htmlDoc ) ;
252252 } else {
253253 doc . srcdoc = '' ;
@@ -275,7 +275,8 @@ EmbedFrame.propTypes = {
275275 name : PropTypes . string . isRequired ,
276276 content : PropTypes . string . isRequired
277277 } ) . isRequired ,
278- isPlaying : PropTypes . bool . isRequired
278+ isPlaying : PropTypes . bool . isRequired ,
279+ basePath : PropTypes . string . isRequired
279280} ;
280281
281282export default EmbedFrame ;
0 commit comments