From c14e1acf6ea7b593a4bf24a37b23af707d3b3452 Mon Sep 17 00:00:00 2001 From: adryd Date: Tue, 5 Dec 2023 12:27:35 -0500 Subject: [PATCH] README.md: update urls --- README.md | 8 ++++++-- src/wpTools.js | 20 ++++++++++++++------ userscriptTemplate.js | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1ede4ed..3db1f1f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ Hi, while this "Works" right now, its not well documented; and a lot is subject to change. ## Installing -The runtime with an example config for twitter can be installed from https://adryd325.github.io/webpackTools/webpackTools.user.js +The runtime with an example config for twitter can be installed from https://moonlight-mod.github.io/webpackTools/webpackTools.user.js ## Updating -To update to the latest webpackTools runtime while maintaining your existing config, edit your userscript and replace the string after `const runtime = ` with https://adryd325.github.io/webpackTools/webpackTools.runtime.json. +To update to the latest webpackTools runtime while maintaining your existing config, edit your userscript and replace the string after `const runtime = ` with https://moonlight-mod.github.io/webpackTools/webpackTools.runtime.json. ## How to determine if something is Webpack 4 or Webpack 5 TODO: actually explain this @@ -18,5 +18,9 @@ if the 3rd entry is a function it's webpack 5 rspack seems to compile to webpack 5 runtime +## Caveats + +Some sites, namely Discord, will start multiple webpack runtimes running on the same webpackChunk object. Duplicate runtimes can be found in `window.wpTools.runtimes`. Injected modules will run multiple times, one for each runtime. + ## Credits A lot of this is based on research by [Mary](https://github.com/mstrodl) and [Cynthia](https://github.com/cynosphere) (HH3), and [Twilight Sparkle](https://github.com/twilight-sparkle-irl/) (webcrack, crispr) \ No newline at end of file diff --git a/src/wpTools.js b/src/wpTools.js index 458ba55..c6cb5ad 100644 --- a/src/wpTools.js +++ b/src/wpTools.js @@ -80,7 +80,7 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) { // TODO: recurse in objects function findModulesByExports(keysArg) { if (!webpackRequire.c) { - throw new Error("webpack runtime didn't export its moduleCache") + throw new Error("webpack runtime didn't export its moduleCache"); } const keys = keysArg instanceof Array ? keysArg : [keysArg]; return Object.entries(webpackRequire.c) @@ -105,10 +105,18 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) { return matchModule(funcStr, search); }) .map(([moduleId, moduleFunc]) => { - return { - id: moduleId, - exports: webpackRequire(moduleId), - }; + try { + return { + id: moduleId, + exports: webpackRequire(moduleId), + }; + } catch (error) { + console.error("Failed to require module: " + error); + return { + id: moduleId, + exports: {}, + }; + } }); } @@ -152,7 +160,7 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) { runtimesRegistry[chunkObject] = exportedRequire; } runtimesRegistry[chunkObject] = exportedRequire; - window["wpTools_"+chunkObject] = exportedRequire; + window["wpTools_" + chunkObject] = exportedRequire; } // Mark as processed as to not loose scope if somehow passed to Patcher._patchModules() diff --git a/userscriptTemplate.js b/userscriptTemplate.js index 4a38122..00e3717 100644 --- a/userscriptTemplate.js +++ b/userscriptTemplate.js @@ -13,7 +13,7 @@ (() => { // Example config const config = { - wpToolsEverywhere: true, // not yet implemented + wpToolsEverywhere: true, // Automatically detect webpack objects and inject them with wpTools (not full patching) siteConfigs: [ { name: "twitter", // Required, for documentation and debug logging