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: Prevent race condition #1520

Open marcustyphoon opened 5 days ago

marcustyphoon commented 5 days ago

Description

1514 relies on the fact that fetching a json file and performing an extension storage query will take longer than the browser fetching the main_world script file, as we need the latter to be performed first.

This performs a back-and-forth handshake to confirm that the main_world script file has been executed before proceeding with main install.

Random aside: to improve extension load speed slightly, one can do:

    const [
      installedScripts,
      { enabledScripts = [] }
    ] = await Promise.all([
      getInstalledScripts(),
      browser.storage.local.get('enabledScripts'),
      mainWorldReady
    ]);

but I can't figure out how to make the code not look stupid.

Testing steps

I have no tests for the bad case this prevents, as I can't for the life of me get it to happen.