Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
freemedom opened this issue May 3, 2023 · 11 comments

Comments

@freemedom
Copy link

No description provided.

@freemedom
Copy link
Author

freemedom commented May 3, 2023

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

@freemedom
Copy link
Author

I finally found a solution. Three changes.

@freemedom
Copy link
Author

default.woff2 and two fetch(wasmBinaryFile

@freemedom
Copy link
Author

freemedom commented May 3, 2023

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
Copy link
Author

#63

@freemedom
Copy link
Author

#37

@freemedom
Copy link
Author

@lightninglu10
Copy link

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.

@freemedom
Copy link
Author

freemedom commented Aug 20, 2023

@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
Copy link
Author

freemedom commented Aug 20, 2023

@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

@huanghaiyang
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants