Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target.evaluate and target.evaluateHandle #2438

Closed
ebidel opened this issue Apr 24, 2018 · 1 comment
Closed

Add target.evaluate and target.evaluateHandle #2438

ebidel opened this issue Apr 24, 2018 · 1 comment

Comments

@ebidel
Copy link
Contributor

ebidel commented Apr 24, 2018

Related to #1215.

Lighthouse has started testing its chrome extension using pptr. They currently usecreateCDPSession to inject code into the extension and run methods:

    const targets = await browser.targets();
    const extensionTarget = targets.find(({_targetInfo}) => {
      return _targetInfo.title === 'Lighthouse' && _targetInfo.type === 'background_page';
    });

    if (!extensionTarget) {
      return await browser.close();
    }

    const client = await extensionTarget.createCDPSession();
    const lighthouseResult = await client.send('Runtime.evaluate', {
      expression: `runLighthouseInExtension({
          restoreCleanState: true,
        }, ${JSON.stringify(lighthouseCategories)})`,
      awaitPromise: true,
      returnByValue: true,
    });

It would be nice to make this use case easier:

const lighthouseResult = target.evaluate(cats => {
  return runLighthouseInExtension({restoreCleanState: true}, cats);
}, lighthouseCategories);
@aslushnikov
Copy link
Contributor

It should be possible to create a Page out of extension's background page. So we should simply teach target.page() to work with background_page.

aslushnikov pushed a commit that referenced this issue Jun 14, 2018
This patch teaches `target.page()` method to attach to extension background pages.

Fixes #2438
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants