JavascriptSubtitlesOctopus
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 ''.
It seems that js file in the Web Worker does not support cross origin.
I finally found a solution. Three changes.
default.woff2 and two fetch(wasmBinaryFile
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.
https://github.com/libass/JavascriptSubtitlesOctopus/issues/63
https://github.com/libass/JavascriptSubtitlesOctopus/issues/37
https://github.com/freemedom/Tampermonkey/blob/main/JavascriptSubtitlesOctopus_fix.js
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 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>
@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
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.