Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
fix: BrowserWindow.fromWebContents should work in browser-window-crea…
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon authored and khalwa committed Feb 22, 2023
1 parent 76eefbb commit 970729c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shell/common/gin_helper/trackable_object.h
Expand Up @@ -117,11 +117,11 @@ class TrackableObject : public TrackableObjectBase, public EventEmitter<T> {
~TrackableObject() override { RemoveFromWeakMap(); }

void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) override {
gin_helper::WrappableBase::InitWith(isolate, wrapper);
if (!weak_map_) {
weak_map_ = new electron::KeyWeakMap<int32_t>;
}
weak_map_->Set(isolate, weak_map_id_, wrapper);
gin_helper::WrappableBase::InitWith(isolate, wrapper);
}

private:
Expand Down
12 changes: 12 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -1816,6 +1816,18 @@ describe('BrowserWindow module', () => {
expect(BrowserWindow.fromWebContents(webviewContents)!.id).to.equal(w.id);
await p;
});

it('is usable immediately on browser-window-created', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('window.open(""); null');
const [win, winFromWebContents] = await new Promise((resolve) => {
app.once('browser-window-created', (e, win) => {
resolve([win, BrowserWindow.fromWebContents(win.webContents)]);
});
});
expect(winFromWebContents).to.equal(win);
});
});

describe('BrowserWindow.openDevTools()', () => {
Expand Down

0 comments on commit 970729c

Please sign in to comment.