简体   繁体   English

如何从浏览器控制台调用 function webpackJsonp

[英]How to call function webpackJsonp from browser console

I want to do automatic action on a website but their code has webpack.我想在网站上执行自动操作,但他们的代码有 webpack。 How can I call those functions?我怎样才能调用这些函数?

"object" != typeof globalThis && (globalThis = window),
(this.webpackJsonp = this.webpackJsonp || []).push([[0], {
    BKWD: function(e, t, s) {
        "use strict";
        var h = new class {
            constructor() {
                ...
            }
            _WriteLog(e) {
                ...
            }
        }
    }
}]);

How to call function _WriteLog from browser console.如何从浏览器控制台调用 function _WriteLog。

U have 2 way.你有两种方式。 First and right way - is export needed data from your entry file.第一种也是正确的方法 - 从您的条目文件中导出所需的数据。 For this.为了这。 use Webpack Library, its basic functional of webpack.使用 Webpack 库,其基本功能为 webpack。

https://webpack.js.org/configuration/output/#outputlibrary

  1. Add library option to your webpack config:将库选项添加到您的 webpack 配置:
 output: {
    library: 'MyLibrary',
  },
  1. Export needed data from your main.js or another js从您的 main.js 或其他 js 导出所需的数据
export function hello(name) {
  console.log(`hello ${name}`);
}

3.. That function will be amiable in window. 3.. function 将在 window 中和蔼可亲。

<script>
MyLibrary.hello('webpack');
</script>

... ...

Second way, if u have no sources of webpack.第二种方式,如果你没有 webpack 的来源。 Link the function.链接 function。 Create empty variable in file start, and link needed function after.在文件开头创建空变量,并在之后链接所需的 function。 For example:例如:


var ssst;

"object" != typeof globalThis && (globalThis = window),
(this.webpackJsonp = this.webpackJsonp || []).push([[0], {
    BKWD: function(e, t, s) {
        "use strict";
        ssst = new class {
            constructor() {
                ...
            }
            _WriteLog(e) {
                ...
            }
        }
    }
}]);


console.log(ssst)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM