ipcRendere を使用してレンダラーとメインの間で対話するために使用するブラウザー ウィンドウ オブジェクトが'NodeIntegration=true'あります。github.com などのページでは正常に動作します。残念なことに、StackOverflow は外部の JavaScript ファイルをロードしません。NodeIntegration をオフにすると、正常に動作します。
以下は私のコードです
コンテキスト メニューを使用して、選択したオブジェクトを右クリックします o クラスを識別し、同期メッセージとして渡します
click: () => {
let codex = `
var ipc = require('electron').ipcRenderer;
var identified = document.elementFromPoint(${params.x}, ${params.y});
console.log(ipc.sendSync('synchronous-message', identified.className.toString()));
`;
mainWindow.webContents.executeJavaScript(codex);
//mainWindow.webContents.inspectElement(params.x,params.y)
}
ipcMain.on('synchronous-message', (event, arg) => {
console.log(arg) // prints class name
event.returnValue = 'pong'
})
ページの読み込みが完了すると、 Dom インスペクターと Jquery が読み込まれます
mainWindow.webContents.on('did-finish-load', ()=>{
let code = `
let $ = require('jquery')
const DomInspector = require('dom-inspector');
const inspector = new DomInspector({
});
inspector.enable()
`;
mainWindow.webContents.executeJavaScript(code);
});
出力
ノード統合をオフにすると機能しますが、dom-inspector js を挿入する方法がわかりません。を使用し<webview>てスクリプトをプリロードする必要がありますか、何かアイデアはありますか?
