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

[API request] Expose the Chrome DevTools target as a page #9371

Closed
elliette opened this issue Dec 6, 2022 · 9 comments · Fixed by #10812
Closed

[API request] Expose the Chrome DevTools target as a page #9371

elliette opened this issue Dec 6, 2022 · 9 comments · Fixed by #10812
Assignees
Labels

Comments

@elliette
Copy link

elliette commented Dec 6, 2022

Bug description

Filing a new issue instead of reopening #4247 where this was first proposed (it was closed in 2019 because it was believed the reporter was the only client trying to use Puppeteer to test a panel added to Chrome DevTools by their Chrome extension, from the comments / recently opened issues it seems that is no longer the case).

As described in #4247 (comment), currently the only way to interact with a panel added to Chrome DevTools by a Chrome extension is to use a hack to set the target type to page:

devtoolsTarget._targetInfo.type = 'page';

This hack is used by the puppeteer-devtools library (code pointer) which was recently cited in #9327 as a way to test a Chrome Extension devtools panel.

Why this doesn't work for my use case:

I'm using the Dart language wrapper of Puppeteer to test my Chrome extension (which is also written in Dart). Because Dart is a strongly-typed language that prevents access to private members (such as _targetInfo), this hack is not possible. I could ask the owner of the Dart Puppeteer implementation to expose this hack in their API, but it seems like a better solution for Puppeteer itself to support this as a real use case and not as a hack.

From #4247 (comment), it sounds like supporting this as an actual use case would be possible.

Thank you!

Puppeteer version

N/A

Node.js version

N/A

npm version

N/A

What operating system are you seeing the problem on?

macOS

Configuration file

No response

Relevant log output

No response

@OrKoN
Copy link
Collaborator

OrKoN commented Dec 6, 2022

It should be possible to re-define what Puppeteer considers to be a page via the isPageCallback: https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/services/puppeteer/PuppeteerConnection.ts;l=90;drc=a30fb93648955c875c7fac7d30eee58d2dd80819

Although accessing the callback requires using some internal APIs, would it work for your use case in general?

@elliette
Copy link
Author

elliette commented Dec 7, 2022

It should be possible to re-define what Puppeteer considers to be a page via the isPageCallback: https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/services/puppeteer/PuppeteerConnection.ts;l=90;drc=a30fb93648955c875c7fac7d30eee58d2dd80819

Although accessing the callback requires using some internal APIs, would it work for your use case in general?

This would potentially work. However, unless I'm misunderstanding, it seems like the client would then have determine whether any target is a page or not, not just the Chrome DevTools target? Ideally it would be nice to have a way to defer back to Puppeteer if we are uninterested in specifying whether the target is a page. Eg:

function isPageTargetCallback(target) {
  if (target.url.startsWith('devtools://devtools') {
    return true;
  }
  // Defer to Puppeteer:
  return isPageTargetByDefault(target);
}



@OrKoN
Copy link
Collaborator

OrKoN commented Dec 8, 2022

@elliette that's why it's not a public API yet

@elliette
Copy link
Author

elliette commented Dec 8, 2022

Adding @xvrh who owns https://github.com/xvrh/puppeteer-dart - thoughts on isPageCallback? This might be something the Dart Puppeteer package could add itself, even without Puppeteer opening it up as a public API

@OrKoN
Copy link
Collaborator

OrKoN commented Dec 9, 2022

@elliette if I recall correctly, DevTools in undocked mode is reported as a page. Perhaps that would be helpful but I am not sure if you can start it undocked.

@OrKoN
Copy link
Collaborator

OrKoN commented Dec 9, 2022

Related #9262

@elliette
Copy link
Author

@elliette if I recall correctly, DevTools in undocked mode is reported as a page. Perhaps that would be helpful but I am not sure if you can start it undocked.

In experimenting with this, I was able to simulate undocking DevTools by getting its URL and then opening a new page with that URL. However, this new DevTools in a page does not have the panels added by my Chrome Extension.

@thuey
Copy link

thuey commented Jul 10, 2023

Any updates on this? The workaround mentioned in the OP is no longer possible for JavaScript either. I do see there is an "internal" _isPageTarget on the BrowserConnector, though, that might be another workaround:

_isPageTarget?: IsPageTargetCallback;

@OrKoN
Copy link
Collaborator

OrKoN commented Jul 11, 2023

@thuey no updates

OrKoN added a commit that referenced this issue Aug 30, 2023
While DevTools won't show up in the `Browser.pages()`
it would be available via its target.

Closes #9371
OrKoN added a commit that referenced this issue Aug 30, 2023
While DevTools won't show up in the `Browser.pages()`
it would be available via its target.

Closes #9371
OrKoN added a commit that referenced this issue Aug 30, 2023
While DevTools won't show up in the `Browser.pages()`
it would be available via its target.

Closes #9371
OrKoN added a commit that referenced this issue Aug 30, 2023
While DevTools won't show up in the `Browser.pages()`
it would be available via its target.

Closes #9371
OrKoN added a commit that referenced this issue Aug 30, 2023
While DevTools won't show up in the `Browser.pages()`
it would be available via its target.

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

Successfully merging a pull request may close this issue.

3 participants