summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/examples/oopif.js
blob: 6ed79f9ced1070136ca7b92146ae77ce62a676f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * @license
 * Copyright 2020 Google Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

'use strict';

const puppeteer = require('puppeteer');

async function attachFrame(frameId, url) {
  const frame = document.createElement('iframe');
  frame.src = url;
  frame.id = frameId;
  document.body.appendChild(frame);
  await new Promise(x => {
    return (frame.onload = x);
  });
  return frame;
}

(async () => {
  // Launch browser in non-headless mode.
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();

  // Load a page from one origin:
  await page.goto('http://example.org/');

  // Inject iframe with the another origin.
  await page.evaluateHandle(attachFrame, 'frame1', 'https://example.com/');

  // At this point there should be a message in the output:
  // puppeteer:frame The frame '...' moved to another session. Out-of-process
  // iframes (OOPIF) are not supported by Puppeteer yet.
  // https://github.com/puppeteer/puppeteer/issues/2548

  await browser.close();
})();