AprilSylph / XKit-Rewritten

🧰 The enhancement suite for Tumblr's new web interface
GNU General Public License v3.0
274 stars 44 forks source link

Main world injection: Execute functions without delay; refactors #1514

Closed marcustyphoon closed 5 days ago

marcustyphoon commented 6 days ago

Description

This adjusts the method used to inject code into the unsandboxed "main world." The goal is to begin the execution of an injected function within the same event loop invocation that it is called in when possible; this both helps avoid UI jank and helps reduce the need to handle race conditions resulting from other page mutations occurring between the call and execution (crashes due to processing detached elements).

Also included are some additional refactors of #1466.

There are a number of methods to do "instant" main world script injection; this one uses a cached dynamic import to load script body files, bubbled custom events to request their execution and communicate their result, and the event target of said bubbled event and the this property on the script function to communicate the target element when needed.

Yes, I actually found a use for Function.prototype.bind/Function.prototype.apply; only took about a million years. No, page_context.js probably isn't in the right place in the repo.

Previously: #1467; preceding work is linked in each PR.

Resolves #1513 (you can't do that anymore, can you)

Testing steps

marcustyphoon commented 6 days ago

Smoke tested in Safari again, and by "smoke tested" I mean "I spent *checks time tracker* half an hour freaking out over Safari not loading anything from the new directory until I realized just rebuilding in xcode is insufficient and you apparently need to run xcrun safari-web-extension-converter [sourcedir] --rebuild-project [destination].xcodeproj or something I guess. anyway show originals seems to work."

AprilSylph commented 5 days ago

Will also need a docs update for src/main_world/. Let's do that separately though...

AprilSylph commented 5 days ago

Will get to TimelineV2 reviews after supper (~2hrs' time?)

marcustyphoon commented 5 days ago

Will also need a docs update for src/main_world/. Let's do that separately though...

Oh, right!

marcustyphoon commented 5 days ago

I feel like I should be bikeshedding the merge commit title more but that's kind of a stupid thought huh. Well—whatever, it can get renamed for the changelog.

marcustyphoon commented 5 days ago

...Huh. I guess you actually can close a PR with another PR. Okay then.