microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.61k stars 3.65k forks source link

[BUG] inconsistency with OOPIF #5815

Closed gilles-yvetot closed 3 years ago

gilles-yvetot commented 3 years ago

Context:

Code Snippet

I have created a small repo here:

But the 2 main parts are those

Playwright launch script

const { chromium } = require('playwright')
const path = require('path')
;(async () => {
  const EXTENSION_PATH = path.resolve('./ext')
  const context = await chromium.launchPersistentContext(`userDataDir`, {
    defaultViewport: null,
    headless: false,
    timeout: 0,
    devtools: true,
    ignoreDefaultArgs: [
      `--no-sandbox`,
      `--disable-default-apps`,
      `--disable-dev-shm-usage`,
      `--disable-sync`,
      `--disable-hang-monitor`,
      `--disable-extensions`,
      `--enable-automation`,
      `--password-store=basic`,
      `--use-mock-keychain`,
      `--disable-popup-blocking`,
      `--disable-prompt-on-repost`,
      `--force-color-profile=srgb`,
      `--disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies`,
      `--disable-background-timer-throttling`,
      `--disable-backgrounding-occluded-windows`,
      `--disable-ipc-flooding-protection`,
      `--disable-renderer-backgrounding`,
      `--disable-background-networking`,
      `--disable-client-side-phishing-detection`,
      `--disable-component-extensions-with-background-pages`,
      `--metrics-recording-only`,
      `--no-first-run`,
    ],
    args: [
      `--profile-directory=Default`, // always launch default
      `--load-extension=${EXTENSION_PATH}`,
      `--allow-insecure-localhost`, // to make sure that we can communicate to local wss
    ],
  })

  const page = await context.newPage()
  await page.goto('https://google.com/', { waitUntil: `networkidle` })
  const frames = await page.mainFrame().childFrames()
  console.log('frames.length', frames.length) // frame is visible
})()

Extension content script

chrome.extension.sendMessage({}, function (response) {
  var readyStateCheckInterval = setInterval(function () {
    if (document.readyState === 'complete') {
      clearInterval(readyStateCheckInterval)
      debugger
      const iframe = document.createElement(`iframe`)
      iframe.src = 'https://playwright.dev/'
      iframe.id = 'myFrame'
      Object.assign(iframe.style, {
        position: `absolute`,
        top: 0,
        left: 0,
        width: 500,
        height: 500,
      })
      document.documentElement.appendChild(iframe)
    }
  }, 10)
})

Describe the bug

I have multiple issues with OOPIF but they are inconsistent. There is one I could repro everytime though. I cannot select an element with the devtools selector inside the injected iframe. PW detects it but it looks the devtools don't detect it.

avodovnik commented 3 years ago

@JoelEinbinder can you have a look at this?

JoelEinbinder commented 3 years ago

To clarify, the issue here is that DevTools can't see the injected frame? Or is there something broken with playwright itself.

gilles-yvetot commented 3 years ago

@JoelEinbinder I don't know if they are related but yes Devtools could not see the iframe when connected with PW but could see them fine without PW. There were other inconsistencies but they are not 100% reproducible. We actually had the same with pptr a year ago, and switching to PW fix them

JoelEinbinder commented 3 years ago

@dgozman do you have any thoughts here? I think we pass it on to the DevTools team. Sounds like a frontend problem.

gilles-yvetot commented 3 years ago

@JoelEinbinder my guess was there is a new flag added by PW because it worked without PW. But you know more than me!

dgozman commented 3 years ago

@dgozman do you have any thoughts here? I think we pass it on to the DevTools team. Sounds like a frontend problem.

Yeah, I've seen similar issues myself. I am not surprised, given how much special OOPIF code we have. I guess having Playwright attached may affect some timings to make the issue more prominent, but it still sounds like a frontend issue.

gilles-yvetot commented 3 years ago

@dgozman I know that's not supported, but I have many problems with Chrome during extension testing. Most likely they are async/timing issues like you mention because they don't always occur

dgozman commented 3 years ago

@dgozman I know that's not supported, but I have many problems with Chrome during extension testing. Most likely they are async/timing issues like you mention because they don't always occur

Please file them as separate issues, we'll do our best to fix them! This one is related to Chrome DevTools that we do not control, so it is harder to get traction. Other issues that might be Playwright-specific we'll be easier to fix.

pavelfeldman commented 3 years ago

Closing as per above, in anticipation for fine-grained issues. Thanks for reporting them, sorry I have to close this to keep our bug database actionable.