Reputation: 1588
I tried adding a custom property on the main browser window, but when tried to access i am just getting undefined.
Upon the creation of the main window I add a custom property.
let win = new electron.BrowserWindow();
win.sampleProperty = 'sample value';
But when accessing it cant retrieve the value of the sampleProperty
.
let bw = browserWindow.getFocusedWindow();
console.log(bw.sampleProperty) // This is undefined
I'd used the getFocusedWindow()
because it will be triggered on menu click.
What I am missing here why bw.sampleProperty
is undefined.
Thanks.
Upvotes: 4
Views: 2282
Reputation: 1588
I just end app adding the property to the browserWindowOptions
This is how to do it:
Upon on creation of the browserWindow
just add your property on the constructor.
let win = new electron.BrowserWindow({
show: false,
customProperty: 'sample' // And here it is.
});
Then you can access it on the browserWindowOptions
let customProp = BrowserWindow.getFocusedWindow()
.webContents
.browserWindowOptions.customProperty;
Upvotes: 5