ruifigueira / playwright-crx

Playwright for chrome extensions
Apache License 2.0
81 stars 15 forks source link

[Question] Run recorder inside a Iframe #20

Closed omkarK06 closed 2 months ago

omkarK06 commented 3 months ago

Question: Recorder-crx records user interactions from that tab as we attach the tab id to the crx app. But is it possible to attach iframe as document from the tab and record interactions only from the iframe.

ruifigueira commented 3 months ago

Yes, as long as the iframe belongs to an attached page, it should record actions in that iframe.

Did you have problems with nested iframes not being recorded?

omkarK06 commented 3 months ago

Yes faced problems in this case, where the main web application tab to which the recorder is attached and the iframe content are sourced from different domains (Both are different domains).

End Goal The iframe document (a different domain or website rendered in iframe) is embedded within the web application dynamically (by user entered url), and I am specifically interested in recording the user interactions within this iframe only, not the surrounding web application. The goal is to exclusively capture and generate test scripts for events that occur within the iframe's document.

I would be happy to discuss this use case and contribute to this project.

ruifigueira commented 3 months ago

I understand. I tried it here and did replicate the issue with the following test:

test("should work in cross-domain iframes", async ({ runCrxTest }) => {
  await runCrxTest(async ({ page }) => {
    await page.goto('https://www.srimax.com/cross-domain-iframe-using-html5/');
    await page.frameLocator('iframe[title="Twitter Follow Button"]').getByRole('link', { name: 'Follow' }).click();
    await page.waitForEvent('popup');
  });
});

Let me investigate it and get back to you.

ruifigueira commented 3 months ago

It seems to be some limitation of Page.getFrameTree on chrome.debugger.

In native playwright, the same Page.getFrameTree call returns the full frame tree (cross-domain iframes included), while using chrome.debugger it doesn't return cross-domain frames.

I'll probably open an issue in chromium for that.

ruifigueira commented 3 months ago

upstream bug: https://issues.chromium.org/issues/333981074

ruifigueira commented 2 months ago

@omkarK06 I tried with chrome canary and it works properly there (apparently they implemented some CDP instructions on chrome.debugger that were missing).

Can you give it a try?

omkarK06 commented 2 months ago

@ruifigueira Thanks for the quick follow up. Thats great, I will try once.

ruifigueira commented 2 months ago

Actually, it is not working, because I have to change a few things. Hopefully in the next version this will be working!

ruifigueira commented 2 months ago

@omkarK06 I just released version 0.6.0 which already supports out-of-process iframes, but only for chrome 126+, which is expected to be stable next month.