TheoXiong / electron-find

:mag: Find all matches for the text in the web page

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Find with multiple <webviews>

madprops opened this issue · comments

Hello. I'm using ElectronFind on a BrowserWindow that has multiple webview elements inside.
Using it works. But there are several issues.

  1. When there are multiple webviews visible and I call openFindWindow() and search, results get highlighted on all webviews but pressing Enter to go next, only works on the first webview.

  2. I would prefer to limit the search to a specific webview. For instance openFindWindow(webview) --- Is that possible?

    Bone.find = new FindInPage(remote.getCurrentWebContents())

    ipcRenderer.on('on-find', (e, args) => 
    {
        Bone.find.openFindWindow()
    })

Hi @madprops and thank you for your interest in ElectronFind component.

I add a new example about searching in specific webview.
For the detail, you can see the commit:

0b70f0ce5d08a1c548142fb5944d6393fd032894

Run the example with:

npm run e2

image

Thank you. I'm having some trouble making it work. I tried e2 and it works there. I'm not sure what I'm doing wrong.

I create webviews dynamically, creating them replacing them with new ones often.

In dom-ready I do this:

Bone.space(1).find_1 = new FindInPage(webview.getWebContents())

Calling Bone.space(1).find_1.openFindWindow() shows the window but search doesn't work:

II4M5vU

I even tried attaching it manually afterwards to check.

Also when I try removing the instance before replacing the webview with another one, I do:

    let find = Bone.space(1).find_1

    if(find)
    {
        find.destroy()
        find = null
    }

And I get:

/home/yo/code/Bone/node_modules/electron-find/src/findInPage.js:222 Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
    at FindInPage.removeElement (/home/yo/code/Bone/node_modules/electron-find/src/findInPage.js:222)

I'm attaching a find to every webview.

I have no idea what I'm doing wrong

Here's some raw code which might provide more information:

    wv.addEventListener('dom-ready', function()
    {
        Bone.on_webview_dom_ready(this)
    })

// What to do when a webview is dom ready
Bone.on_webview_dom_ready = function(webview)
{
    let num = parseInt(webview.dataset.num)
    let space_num = parseInt(webview.dataset.space)

    if(!Bone.space(space_num)[`find_${num}`])
    {
        Bone.space(space_num)[`find_${num}`] = new FindInPage(webview.getWebContents())
    }
}

// And when I'm going to replace it

    let space = Bone.space()
    let find = space[`find_${num}`]

    if(find)
    {
        find.destroy()
        find = null
    }

    Bone.replace_element(rep, wv)

This is in Electron 5.0.2 btw

I've been trying to implement find myself using Electron 5.02, but it seems webview.findInPage() might be broken.

Ok testing on a new Electron 5.0.2 findInPage works, I'm doing something wrong.
Edit: It was a problem with the electron-context-menu library. Attaching a context menu made findInPage not work.

So, have you confirmed that your issue has nothing to do with this component?
By the way, have you solved your issue?

Yep, it's solved. Thank you.