LucianoGanga / simple-headless-chrome

Simple abstraction to use Chrome as a Headless Browser with Node JS
MIT License
217 stars 50 forks source link

FrameID selection broken for framesets? #51

Open strabbit opened 7 years ago

strabbit commented 7 years ago

If I have a document that contains a frameset:

<frameset cols="*">
  <frame id="the_frame" name="the_frame" src="frame.html">
</frameset>

And that frame file contains a button:

<button id='the_button'>Click me</button>

I expect the following code to work:

async function navigateWebsite() {
        await browser.init();
        const mainTab = await browser.newTab( { privateTab: false } );
        await mainTab.goTo( '...' ); // URL of page containing iframe
        await mainTab.wait( 1000 );
        let frames = await mainTab.getFrames();
        frames = frames.filter( f => f.name === 'the_frame' );
        const frame = frames[0].id;
        await mainTab.click( '#the_button', frame );
} );

Instead I receive this error:

(node:18709) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: No node with given id found
(node:18709) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

What is the the correct value to pass as frameId? Is this a bug or am I just misunderstanding usage?

mmarsella commented 7 years ago

Hey Strabbit,

If you log what the output of let frames = await mainTab.getFrames();, what do you get?

I've been using this library a lot lately - so I may be able to help.

M

strabbit commented 7 years ago
[ { id: '21949.1',
    loaderId: '21949.2',
    url: 'http://strabbit.com/frame-example/frameset.html',
    securityOrigin: 'http://strabbit.com',
    mimeType: 'text/html' },
  { id: '21949.2',
    parentId: '21949.1',
    loaderId: '21949.3',
    name: 'the_frame',
    url: 'http://strabbit.com/frame-example/frame.html',
    securityOrigin: 'http://strabbit.com',
    mimeType: 'text/html' } ]

Meaning I'm passing 21949.2 as frame to mainTab.click.

strabbit commented 7 years ago

I've edited the original post. It works for iframes but not for frames in a frameset.

LucianoGanga commented 7 years ago

Hi @strabbit !

I've never used framesets. I think that the problem that you're having is related to how simple-headless-chrome tries to find the correct scope when you pass a frameId:

https://github.com/LucianoGanga/simple-headless-chrome/blob/master/lib/actions.js#L306

Do you know of a website with framesets so we can make a test case for the scenario that you need? We can modify simple-headless-chrome to support those cases.

Thanks! Lucho

strabbit commented 7 years ago

Thanks @LucianoGanga

http://strabbit.com/frame-example/frameset.html is a very simple frameset example. It's the one I used to verify the issue.

LucianoGanga commented 7 years ago

Thanks! I'll look into it later. I'll let you know if I can fix and upload an example with that (I'll try to make some extra time to prepare a test case too, just to ensure future compatibility).

Cheers! Lucho