JavascriptSubtitlesOctopus icon indicating copy to clipboard operation
JavascriptSubtitlesOctopus copied to clipboard

Failed to construct 'Worker': Script at 'https://libass.github.io/JavascriptSubtitlesOctopus/assets/js/subtitles-octopus-worker.js' cannot be accessed from origin ''.

Open freemedom opened this issue 1 year ago • 11 comments

freemedom avatar May 03 '23 12:05 freemedom

It seems that js file in the Web Worker does not support cross origin.

freemedom avatar May 03 '23 12:05 freemedom

I finally found a solution. Three changes.

freemedom avatar May 03 '23 13:05 freemedom

default.woff2 and two fetch(wasmBinaryFile

freemedom avatar May 03 '23 13:05 freemedom

It took a while to solve the Chinese coding problem. Don't know why set font doesn't work (fonts fallbackFont), eventually to replace the default font https://libass.github.io/JavascriptSubtitlesOctopus/assets/js/default.woff2 in code. I don't know if it's due to the old version, I didn't test the new version 4.

freemedom avatar May 03 '23 14:05 freemedom

https://github.com/libass/JavascriptSubtitlesOctopus/issues/63

freemedom avatar May 03 '23 14:05 freemedom

https://github.com/libass/JavascriptSubtitlesOctopus/issues/37

freemedom avatar May 03 '23 14:05 freemedom

https://github.com/freemedom/Tampermonkey/blob/main/JavascriptSubtitlesOctopus_fix.js

freemedom avatar May 03 '23 14:05 freemedom

Can you explain how to use this fix? I'm trying to use this library and would like to load it in a CDN rather than bundle everything together but I'm not able to get it working.

lightninglu10 avatar Aug 19 '23 21:08 lightninglu10

@lightninglu10 I haven't used it for a while. I remember using this code from this demo at the beginning, but you can take a look at the devtool console and see several cross origin related errors.

<script>
src = "https://libass.github.io/JavascriptSubtitlesOctopus/assets/js/subtitles-octopus.js"

const element = document.createElement('script')
element.setAttribute('type', 'text/javascript')
element.setAttribute('src', src)
document.head.appendChild(element)

            var player = videojs('#test');
            player.ready(function () {
                // This would look more nice as a plugin but is's just as showcase of using with custom players
                var video = this.tech_.el_;
                window.SubtitlesOctopusOnLoad = function () {
                    var options = {
                        video: video,
                        subUrl: '/JavascriptSubtitlesOctopus/subtitles/test.ass',
                        fonts: ['/JavascriptSubtitlesOctopus/fonts/Arial.ttf', '/JavascriptSubtitlesOctopus/fonts/TimesNewRoman.ttf'],
                        //onReady: onReadyFunction,
                        debug: true,
                        workerUrl: '/JavascriptSubtitlesOctopus/assets/js/subtitles-octopus-worker.js'
                    };
                    window.octopusInstance = new SubtitlesOctopus(options); // You can experiment in console
                };
                if (SubtitlesOctopus) {
                    SubtitlesOctopusOnLoad();
                }
            });
        </script>

freemedom avatar Aug 20 '23 02:08 freemedom

@lightninglu10 So I managed to solve a few of the errors. The main thing is to replace the js file of workerUrl with a local function. Then I modified several places in this function. The fonts modification is to adapt to Chinese.

You can see this js file. https://github.com/freemedom/Tampermonkey/blob/main/JavascriptSubtitlesOctopus_fix.js

freemedom avatar Aug 20 '23 02:08 freemedom

The subtitles-octopus-worker.js, subtitles-octopus-worker-legacy.js, and subtitles-octopus-worker.wasm files need to be placed in the same-origin directory of the server, such as nginx, otherwise there will be cross-origin issues.

huanghaiyang avatar Dec 27 '23 10:12 huanghaiyang