Skip to content

Commit

Permalink
fix(devtools): a lot of extension server error: Operation failed: Per…
Browse files Browse the repository at this point in the history
…mission denied (#375)

1. before the console opens DevTools, the dom has not been loaded, and
   many DevTools errors will appear.
  • Loading branch information
BlackHole1 committed Mar 9, 2021
1 parent 0ae6adc commit 55b8d3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/main-app/src/utils/WindowEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ export const windowReadyToShow = (customWindow: CustomSingleWindow) => {
customWindow.window.show();
});
};

export const windowOpenDevTools = (customWindow: CustomSingleWindow) => {
customWindow.window.webContents.once("dom-ready", () => {
// open devTools must be completed after dom ready
// link: https://github.com/electron/electron/issues/12438
if (customWindow.options.isOpenDevTools) {
customWindow.window.webContents.openDevTools();
}
});
};
6 changes: 2 additions & 4 deletions src/main-app/src/utils/WindowManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserWindow, BrowserWindowConstructorOptions, ipcMain, IpcMainEvent } from "electron";
import { windowHookClose, windowReadyToShow } from "./WindowEvent";
import { windowHookClose, windowOpenDevTools, windowReadyToShow } from "./WindowEvent";
import runtime from "./Runtime";
import { constants } from "types-pkg";
import { Subject, zip } from "rxjs";
Expand Down Expand Up @@ -57,9 +57,7 @@ export class WindowManager {

void innerWin.window.loadURL(options.url);

if (options.isOpenDevTools) {
innerWin.window.webContents.openDevTools();
}
windowOpenDevTools(innerWin);

windowHookClose(innerWin);

Expand Down

0 comments on commit 55b8d3d

Please sign in to comment.