subadub
subadub copied to clipboard
Plugin does not work with MAL-sync
Describe the bug
When having the Subadub plugin together with the MAL-sync-plugin ( extension page, github ), the MAL interface does not appear, and the anime is not recognized by it.
When loading the console, an error appears:
Uncaught InternalError: too much recursion isSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:431 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:438 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443 findSubtitlesProperty https://www.netflix.com/watch/70303649?trackId=xxx:443
This error only appears when both extensions are running, disabling either one of them makes it disappear.
I have also reported this on the MAL-sync-repo: link.
Steps to reproduce the behavior: Load both extensions, open Netflix on an anime that MAL-sync normally recognises.
Additional information:
- Browser: Firefox
- Type: Extension
- Url: https://github.com/MALSync/MALSync
Hi @rsimmons , I believe I know this problem. I met it in in my subadub fork.
The dirty trick of replacing JSON.stringify method fails this way when method stringify is called for recursive object. Such objects sometimes exist in Netflix interface. I fixed it by another dirty trick - callig originalStringify and after that originalParse, which safely convert Netflix recursive object into simple nonrecursive object and after that continues custom JSON.stringify method. There must be some better way to do this. But this works and I do no see significant performance decreace.
Here:
https://github.com/met/subfilter/blob/0046a571634fc556c82b5b33953e865e6e173548/dist/content_script.js#L478-L498
const originalStringify = JSON.stringify;
JSON.stringify = function(value) {
if (value === undefined) { // for compatibility JSON.stringify should not raise exception, which will happed if we call originalParse with "undefined" later
return originalStringify.apply(this, arguments);
}
// Many Netflix objects have .toJSON method that findSubtitlesProperty does not handle
// And for cyclic objects will findSubtitlesProperty ends in infinitive recursion, issue #27
// So here we convert object to string and back to JSON-object (that will correctly handle objects with .toJSON methods and cyclic references are removed in this process)
let jsonstring = originalStringify.apply(this, arguments);
value = originalParse.call(this, jsonstring);
// Don't hardcode property names here because Netflix
// changes them a lot; search instead
let prop = findSubtitlesProperty(value);
if (prop) {
prop.unshift(WEBVTT_FMT);
}
return originalStringify.call(this, value);
};