Comments (7)
@himat Frame
object is always the same for the same frame. guid
is a part of the Frame
object, but since it's an internal implementation detail, it might disappear at any moment as well.
from playwright.
@himat Interoperating with CDP is not a goal for Playwright. The use of CDP is an implementation detail. If you'd like to work with CDP directly, feel free to retrieve the frame tree over CDP and call any protocol methods you'd like. Note that Playwright does not guarantee that it won't break after you call some CDP methods, so use it at your own risk.
Also, just wanted to check, but the frame object guid is entirely different from the actual Frame's ID right?
Yes, guid
is a separate randomly generated id.
from playwright.
@himat ID is an internal implementation detail. You can always create a Map<Frame, number>
or use a symbol and lazily auto-generate ID for each frame.
const idMap = new Map<Frame, number>();
function getFrameId(frame: Frame) {
if (!idMap.has(frame))
idMap.set(frame, idMap.size + 1);
return idMap.get(frame)!;
}
from playwright.
@dgozman But that relies on only having one instance of a given Frame
to make sure the reference comparison works right?
i.e. If I get a Frame at one point and store it in variable f1
and a Frame again later and store it in f2
(and say these came from two separate calls to page.frames()
), then I want to ensure that if they're the same underlying frame that f1 === f2
should equal true
.
And even if a Frame changes over time, does Playwright itself manage the frame internally to make sure that it always only has one reference to each Frame?
from playwright.
I also noticed that playwright has an internal only guid
field. Is that also stable, or are the guid
assigned to each instance and therefore wouldn't work? In other words, are these guid
s, a unique UI on the reference or on the actual underlying value?
from playwright.
@dgozman, ok so using Frame
makes sense for that
But I have another usecase, where I need to reach into the CDP to listen for events since playwright does not expose these
const cdpClient = await page.context().newCDPSession(page)
await cdpClient.send("DOM.enable")
await cdpClient.send("Network.enable")
cdpClient.on("Network.requestWillBeSent", onNavigationStart)
function onNavigationStart(params: Protocol.Network.RequestWillBeSentEvent) {
const frames = page.frames()
const navigationFrameId = params.frameId
const isMainFrame = frames.find((frame) => frame.<ID??> === navigationFrameId) !== -1
if (!isMainFrame) return
...
}
As you can see, I want to detect the navigation start for a page, and the RequestWillBeSentEvent gives me back a frameId
, and I want to only run this algorithm on the main frame, but I can't do that here since you don't expose the frame ID.
Also, just wanted to check, but the frame object guid
is entirely different from the actual Frame's ID right? Was wondering if I could even use the guid
here even if temporarily even though its internal
from playwright.
Closing as per above. If you encounter more problems, please file a new issue by filling in the "Bug Report" template.
from playwright.
Related Issues (20)
- [Docs]: Running ui mode docs incomplete HOT 2
- Using storageState in the general use config does not work - but works in the projects array HOT 1
- [Bug]: Exit code 0 when crashes with out of memory error HOT 3
- [Bug]: testIdAttribute via config does not take effect in `globalSetup` function HOT 1
- [Bug]: UI mode is showing tags as pill and as text HOT 2
- [Bug]: ADO Pipeline JUnit Report not showing attachments, however the logs show [[ATTACHMENT|filename]] HOT 3
- [Feature]: Ability to extend the trace information HOT 9
- [Feature]: Add tracing class in page like puppeteer HOT 3
- [Feature]: add page method start record HOT 1
- [Feature]: Add option to filter Locators by visibility HOT 2
- [Bug]: element.tagName.toUpperCase is not a function HOT 4
- [Bug]: WebKit page screenshots are missing alpha channel in Linux HOT 4
- Running playwright offline
- [Feature]: Playwright support on rocky linux HOT 5
- usage of test.slow()
- [Bug]: Can't unmount -> remount with @playwright/experimental-ct-react17 HOT 2
- [Bug]: UI seems to lock on Windows making tests time out HOT 5
- [Bug]: Reusing page between tests when running serially adds extra teardown time per test HOT 3
- [Bug]: Intermittent Undetermined Error [IP: 185.125.190.36 80] when running `npx playwright install --with-deps` on CI HOT 2
- Query regarding a piece of code HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright.