martok / palefill

Inject Polyfills for various web technologies into pages requiring them
https://martok.github.io/palefill/
Mozilla Public License 2.0
79 stars 9 forks source link

can't add customElements to pixiv #9

Closed roytam1 closed 1 year ago

roytam1 commented 2 years ago

I tried to add new entry in const _definitions:

    {
        selector: ["s.pximg.net/www/js/build/vendors*.js$script"],
        fix: ["$script","std-customElements"]
    },

but it seems that I can't get rid of missing customElements error:

13:01:16.488 PF:  applied fixes to  "https://s.pximg.net/www/js/build/vendors~spa.80859c2e9f4c0ee3303e.js" :  Array [ "$script", "std-customElements" ] 1 util.js:72
13:01:17.106 TypeError: window.customElements is undefined 1 vendors~spa.80859c2e9f4c0ee3303e.js:411:25
    [1778] https://s.pximg.net/www/js/build/vendors~spa.80859c2e9f4c0ee3303e.js:411:25
    r https://s.pximg.net/www/js/build/runtime.e71bdc73f3e32597d30f.js:8:8
    <anonymous> https://s.pximg.net/www/js/build/spa.20de562f99c5c0ff86a6.js:10040:21
    r https://s.pximg.net/www/js/build/runtime.e71bdc73f3e32597d30f.js:8:8
    <anonymous> https://s.pximg.net/www/js/build/spa.20de562f99c5c0ff86a6.js:9796:754
    r https://s.pximg.net/www/js/build/runtime.e71bdc73f3e32597d30f.js:8:8
    a https://s.pximg.net/www/js/build/runtime.e71bdc73f3e32597d30f.js:5:40
    c https://s.pximg.net/www/js/build/runtime.e71bdc73f3e32597d30f.js:4:30
    <anonymous> https://s.pximg.net/www/js/build/spa.20de562f99c5c0ff86a6.js:1:2
roytam1 commented 2 years ago

by the way, I tested bundled customElements polyfill is working (by copying it to greasemonkey script with @grant unsafeWindow and @run-at document-start, but I'm getting another error on UXP-based browsers:

Timestamp: 31/3/2022 13:57:57
Error: Error: Permission denied to access property "prototype"

Source File: https://s.pximg.net/www/js/build/vendors~spa.80859c2e9f4c0ee3303e.js
Line: 386
martok commented 2 years ago

Can't test it right now, but just a quick note: you'll want to inject the polyfill into the site that uses the script, not the script itself. Similar to the entry for gitlab.com.

$script fixes are mostly for fixing language/syntax problems in the script itself.

roytam1 commented 2 years ago

but I'm getting another error on UXP-based browsers

maybe I hit greasemonkey bug here.

roytam1 commented 2 years ago

Can't test it right now, but just a quick note: you'll want to inject the polyfill into the site that uses the script, not the script itself. Similar to the entry for gitlab.com.

$script fixes are mostly for fixing language/syntax problems in the script itself.

tried but not working. but I got success by adding pixiv.net to gitlab domain list in justoff's github-wc-polyfill-1.2.17.xpi

martok commented 2 years ago

tried but not working. but I got success by adding pixiv.net to gitlab domain list in justoff's github-wc-polyfill-1.2.17.xpi

Then it should work here. I'll see what's going on when I get home.

Wait, you're the K-Meleon person? Knew the name sounded familiar 🙂 I have a certain interest in getting this addon working in Goanna-KM (specifically, the Win2k build) even if I don't personally use it, is this a thing that can be done? I'm not sure if Goanna 2.x maybe misses something essential...

roytam1 commented 2 years ago

is this a thing that can be done? I'm not sure if Goanna 2.x maybe misses something essential...

haven't ever tried on goanna2, but on goanna3 (i.e. NM27, current KMG76) lacks some variation of for..of syntax, making palefill not working, but justoff's github-wc-polyfill works on goanna3 (at least on adding window.customElements polyfill).

martok commented 2 years ago

haven't ever tried on goanna2, but on goanna3 (i.e. NM27, current KMG76) lacks some variation of for..of syntax, making palefill not working, but justoff's github-wc-polyfill works on goanna3 (at least on adding window.customElements polyfill).

In that case const and let might be close calls as well. I'm not super hyped about some more recent JS language constructs, but those were actually useful... don't really want to write code without them.

And on this topic: the rule needs to match the domain exactly, including the www. in this case. This may change in the future with wildcard domain patterns, but for now it is what it is.

dilworks commented 2 years ago

First things first, thank you guys very much for Palefill! It even works nicely with my SeaMonkey setup, bringing back some sanity in a sea of Chrome-induced web vomit...

Hate to reopen this issue, but even with the addon default rules, I can't still logon to Pixiv: while the logon page will load and attempt to log me in, Pixiv's server response is a 400 Invalid Request JSON blob telling me that the logon request is most likely malformed or missing essential parameters. Oh, and the logon page was still complaining on the console about window.customElements still being undefined! Turns out that the default ruleset only covers www.pixiv.net, but the logon form is served from accounts.pixiv.net instead.

The solution (to me) turned out to be easy: add accounts.pixiv.net to the default ruleset, and it will let me logon without issue. I do see some minor secondary effects under one or more "Error: Failed to construct a custom element: The constructor was not registered with customElements." messages logged to console, but Pixiv seems to work fine, at least for casual browsing.

martok commented 2 years ago

"Error: Failed to construct a custom element: The constructor was not registered with customElements."

Some debugging shows that the missing constructor is undefined... there is clearly something more broken here. But if it works, it works :shrug:

martok commented 1 year ago

That weird error is still there even after a few updates. Who knows.