Skip to content

About

`require` bundled Webpack modules from a userscript or extension, on sites you don't control.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

WpRequire

WpRequire is a library for userscripts to interact with Webpack's module chunks. It provides the ability to require Webpack modules and find modules that match a condition, to keep userscripts working through site updates.

Getting Started

Installation

// @require     https://cdn.jsdelivr.net/npm/wp-require@1.0.0/dist/wprequire.js

Usage

const webpack = new WpRequire(webpackChunkname);

// Require a module
const module = webpack(moduleId);

// Find a module
const module = webpack.findModule((m) => Object.hasOwn(m, "createUser"));

// List modules
console.log(webpack.moduleExports);

API

Class: WpRequire

Constructor

new WpRequire(webpackChunk, interceptModuleCalls = false)

  • webpackChunk (Array): The Webpack chunk array. If null is provided, the constructor will attempt to find it using WpRequire.findWebpackChunks().

  • interceptModuleCalls (Boolean): If true, the constructor intercepts module calls to cache their exports. Default is false.

  • Throws:

    • Error if Webpack chunks or the require function cannot be found.

Methods

(...arguments)

Calls wpRequire.require with provided arguments.

require(...arguments)

Calls the Webpack require Calls the Webpack require function with the provided arguments.

findModule(condition[, cachedOnly = false])

  • condition (Function): A function that takes module exports as an argument and returns a boolean indicating if the module matches the condition.

  • cachedOnly (Boolean): If true, only searches cached modules. Default is false.

  • Returns: The exports of the first module that matches the condition, or null if no match is found.

static findWebpackChunks()

  • Returns: An array of Webpack chunk arrays found in the global window object.

Properties

cachedModules

An object storing the exports of intercepted modules.

modules

An object representing all the modules in the Webpack bundle.

moduleExports

Getter that requires all modules exports.

About

`require` bundled Webpack modules from a userscript or extension, on sites you don't control.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages