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

Plugin does not work with MAL-sync #30

Open
ThomasP6t opened this issue Aug 23, 2021 · 1 comment
Open

Plugin does not work with MAL-sync #30

ThomasP6t opened this issue Aug 23, 2021 · 1 comment

Comments

@ThomasP6t
Copy link

ThomasP6t commented Aug 23, 2021

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:

@met
Copy link

met commented Sep 5, 2021

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);
  };

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

2 participants