跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • Electron 中使用 webRequest.onBeforeRequest 重定向请求 URL 失败
未分類
4 9 月 2020

Electron 中使用 webRequest.onBeforeRequest 重定向请求 URL 失败

Electron 中使用 webRequest.onBeforeRequest 重定向请求 URL 失败

資深大佬 : skylee03 2

如题,我想用 Electron 中 webRequest.onBeforeRequest 重定向某个网站的 swf 资源。之前用 Chrome 插件实现时,用 chrome.webRequest.onBeforeRequest.addListener 成功达到想要的效果,但是用 Electron 实现时,console.log("Test Passed.")这句话可以被正常触发,但是最终加载的资源却仍然是原地址的资源。

const { app, BrowserWindow } = require('electron') const { resolve } = require('path') app.commandLine.appendSwitch('ppapi-flash-path', resolve(__dirname, 'pepflashplayer64_32_0_0_314.dll')) app.commandLine.appendSwitch('ppapi-flash-version', '32.0.0.314')  function createWindow() {     win = new BrowserWindow({   autoHideMenuBar: true,   show: false,   fullscreen: false,   webPreferences: {plugins: true}  })  win.maximize()  win.webContents.openDevTools()  win.webContents.session.webRequest.onBeforeRequest(async ({url}, callback) => {   var reg = new RegExp("http://<source-domain>/test~[0-9]*.swf", 'g')   if(reg.test(url)) console.log("Test Passed.")   callback(reg.test(url) ? {redirectURL: "http://<target-domain>/test.swf"} : {})  })  win.loadURL('http://<source-domain>')     win.on('closed', () => {win = null}) } app.on('ready', createWindow) 

大佬有話說 (0)

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具