Skip to content

Instantly share code, notes, and snippets.

View HeGanjie's full-sized avatar

Bruce He HeGanjie

View GitHub Profile
@HeGanjie
HeGanjie / importCompat.ts
Created October 29, 2021 08:50
dynamic import compact chrome 63
async function importCompat(nodeBookModuleUrl: string) {
try {
// const { default: notebook } = await import(/*webpackIgnore: true*/ nodeBookModuleUrl)
// 用 eval 绕过打包逻辑
return await eval(`import('${nodeBookModuleUrl}')`)
} catch (e) {
// https://github.com/guybedford/es-module-shims#shim-mode-option
window.esmsInitOptions = {
shimMode: true // default false
} as any
@HeGanjie
HeGanjie / index.ts
Created March 18, 2022 02:28
intercept object function call
function interceptFuncCall(object: any, fnName: any, fnReplace: (originalObj: any, ...originalArgs: any[]) => any) {
const obj = new Proxy(object, {
get: function(target, propKey, receiver) {
if (propKey === fnName) {
return function() {
return fnReplace(target, ...arguments)
}
}
const val = Reflect.get(target, propKey, receiver)
return val