title: Why does frame selection breaks after page reloads?
body: <p>I am trying to inspect a page with playwright that holds a frame document that when I click a button a banner will appear for a couple of minutes. When it's done the page needs to be reloaded for the banner to disappear. I am checking every 5 minutes automatically until I don't see the banner on the page but when I can only do it for the 1 loop after that the code breaks. What can I do to fix this.</p>
  <p>A possible solution could be going to the iframe link itself but the document breaks if I do that. I wish to avoid doing this. It's not how I would do things if I was manually doing this.</p>
  <p>UnhandledPromiseRejectionWarning: frame.evaluate: Execution Context is not available in detached frame (are you trying to evaluate?)</p>
  <pre><code>const browser = await chromium.launch({ 
      args: [&quot;--start-maximized&quot;, &quot;--disable-notifications&quot;,  '--disable-extensions', '--mute-audio'],
      defaultViewport: null,
      devtools: true,
      slowMo: 50,
      downloadsPath: &quot;D:\\Lambda\\projects\\puppeteer_test\\data&quot;,
  });
  
  // Create a new incognito browser context with user credentials
  const context = await browser.newContext({
      acceptDownloads: true,
      viewport: null,
      storageState: JSON.parse(storageState),
  })
  
  // Create a new page in a pristine context. 
  const page = await context.newPage()
  
  // go to download your information
  await page.goto(&quot;&quot;);
  
  //select child frame
  const frameDocUrl = await (await page.waitForSelector(&quot;iframe&quot;)).getAttribute(&quot;src&quot;)
  const doc = await page.frame({url: frameDocUrl})
  await doc.waitForLoadState('domcontentloaded');
  
  /* waitForFile */
  // refresh every 5 minute until notice of gathering file is gone 
  // then Pending becomes download
  const frameUrl = await doc.url()
  const fiveMinutes = 300000
  let IsGatheringFile = await doc.$(&quot;//div[text()='A copy of your information is being created.']&quot;) ? true: false
  while(IsGatheringFile){
      //reload page
      console.log(&quot;going to reload&quot;)
      await doc.goto(frameUrl)
      
      // wait for 5 minutes
      console.log(`going to start waiting for 5 min starting in ${Date().split(&quot; &quot;)[4]}`)
      await doc.waitForTimeout(fiveMinutes)
      console.log(&quot;finish reloading&quot;)
  
      // check if notice is gone
      IsGatheringFile = await doc.$(&quot;//div[text()='A copy of your information is being created.']&quot;) ? true: false
  }
  console.log(&quot;finish waiting for data&quot;)
  
  console.log(&quot;finish reloading the page until the banner is gone&quot;)
  </code></pre>