#how to destroy webContent with webContentId?

57 messages · Page 1 of 1 (latest)

rain temple
#

webContent has not "destory" method.
In other words, if I want to destroy the webcontent from id then I couldn't do anything.
And I have killed the process for webContent but the pId was became 0 and I can see webContent(not destroyed) in webContents.getAllWebContents().
Could you help me ?
webContents.getAllWebContents().forEach((wc: WebContents) => {
const url: string = wc.getURL();
const pId: number = wc.getOSProcessId();
if ('about:blank' === url) {
if (0 !== wc.getOSProcessId()) {
process.kill(pId);
}
}
});

nocturne merlin
#

for what purpose?

rain temple
#

Hi
Thank you for your reply.

#

I am working on the web browser project based on electronjs.

#

In my project, I have made the task manager for control tabs.

#

This package is what I have posted.

#

To destroy webContent, I have to call process.kill method.
But webContent.getAllWebContents then the killed webContent is still exitance.

#

Thus, I think webContent.destory must be existed.

#

What do you think ?

nocturne merlin
#

webContent is part of BrowserWindow

rain temple
#

yeah

nocturne merlin
#

use destroy of browserwindow

rain temple
#

Then all process will be existed.
If browserwindow has many browserView then how are you going ?

nocturne merlin
#

with browserview api

#

if you able to attach browserview to browserwindow

#

you able to detach it

rain temple
#

yeah, but there might be the undestroyed webContent even if I called browser.removeBrowserView(view).

#

Do you think it's right code ?

nocturne merlin
#

if you able to use it why not

#

but destroying webcontent may also destroy its owner

rain temple
#

Absolutely, webContent doesn't have destroy method.

nocturne merlin
#

its have it

#

its not documented

rain temple
#

It's the sample code by some guys.

#

yeah,but if I call the destroy method then it would occur an errror.

nocturne merlin
#

what error?

tired mantle
#

Typescript types don't list the destroy method as being available, but it is 🙂

#

and you must set the active browserwindow to null or another view before calling destroy

rain temple
#

Hi, Sorry for delay response.

nocturne merlin
#

you mistype

rain temple
#

what do you mean ?

nocturne merlin
#

destory

rain temple
#

oh, really sorry.

#

Thank you so much, 🙂

#

why destroy method doesn't exist in documentation ?

nocturne merlin
#

because it is not supposed to be used

rain temple
#

so in generally, we shouldn't use destroy method, shouldn't it?

nocturne merlin
#

no

rain temple
nocturne merlin
#

no, you shouldnt use it

rain temple
#

There is the point I want to destroy webContent by id.

#

in this case, we can call directly destroy method, I think.

#

What do you think ?

nocturne merlin
#

use close of browserwindow

rain temple
#

yah, I have already used it.

#

But there is the case that electron.js don't release webContent when I have set this.browserView = null; and this.window.win.removeBrowserView(view.browserView);

#

So I had to call process.kill to clear the unused webContent.

nocturne merlin
rain temple
#

I understand,

#

Thank you for your supporting me

#

Where are you from ,btw ?

nocturne merlin
#

but closest i find where webcontents.close exists is electron v22

rain temple
#

ok.