dpacassi / disable-javascript

Adds the ability to disable JavaScript on specific sites.
MIT License
272 stars 33 forks source link

port to safari #81

Closed karelbilek closed 3 years ago

karelbilek commented 3 years ago

I like Safari browser on macOS.

It has some weird version of webextensions, that also somehow require to make it a macOS app.

I will try to port it myself first (to learn safari extension logic :)) and then maybe make a PR. Or it can live in my fork forever, I don't know, as you wish, I still need to actually port it first

karelbilek commented 3 years ago

The first thing - Safari doesn't support webRequestBlocking.

I guess that's fine? Most JS is not by webRequest?

karelbilek commented 3 years ago

oh I confused webrequest and websocket.

webRequestBlocking is essential, and the extension just won't work without it. (just tried it. nope won't work.)

Hm. So... I guess we can close this? :D

karelbilek commented 3 years ago

yup

https://developer.apple.com/forums/thread/650840

they have "content blocker", but that is specifically NOT dynamic and it needs to have the file lists pre-written, so cannot be dynamically changed.

https://developer.apple.com/documentation/safariservices/creating_a_content_blocker

https://github.com/calebhicks/ios-safari-content-blocking

boo!

karelbilek commented 3 years ago

seems it can be done dynamically actually, just requires some more hacking

https://stackoverflow.com/questions/32151109/reloading-content-blockers-in-ios

karelbilek commented 3 years ago

this will enable to do per-domain blocking, not per-tab blocking. But it could be hidden for safari I guess.

But it will enable more custom code. Basically safari webextensions always need to have binary app, the JS will contact the binary app and that contacts the blocker. I think that is what adblockers for safari do.

karelbilek commented 3 years ago

ugh there is so much custom code for safari that it's basically a separate project. I will close this for now

karelbilek commented 3 years ago

I got it ba-si-cally working!

https://github.com/karelbilek/disable-javascript

I need to clean it up... but I built it first for myself :D and it works-for-me.

It basically needs 3 different macos binaries next to the extension - the extension helper, main app, and "content blocker", and what I do is send the blocker JSON from the extension, then through some sharing magic it tunnels to the content blocker, and set it there.

There are still some issues with the icon, and with the initialization, but as that is on JS side, it's much easier to debug/fix, as I don't need to delve into Swift/cocoa/XCode. Thx for this