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
Any way to check iframe loaded successfully?? #1361
Comments
If you're using If that's not working, you can use const frame = await page.frames().find(f => f.name() === 'ifrw');
await frame.waitForSelector('#selector');
const button = await frame.$('#selector');
await button.click(); Note: this will be easier with #1007, tracks |
I'm not using page.goto(), the frame is in a modal window within the same page. The way you indicated me has not worked for me |
@fran0254 there are frame events that notify about frame structure changes: You can wait until there's a desired frame attached with |
@aslushnikov Could you explain how I can check these three events that you mention to me? attached the frame Frame {
_client:
Session {
domain: null,
_events:
{ 'Page.frameAttached': [Function],
'Page.frameNavigated': [Function],
'Page.frameDetached': [Function],
'Runtime.executionContextCreated': [Function],
'Network.requestWillBeSent': [Function: bound _onRequestWillBeSent],
'Network.requestIntercepted': [Function: bound _onRequestIntercepted],
'Network.responseReceived': [Function: bound _onResponseReceived],
'Network.loadingFinished': [Function: bound _onLoadingFinished],
'Network.loadingFailed': [Function: bound _onLoadingFailed],
'Page.loadEventFired': [Function],
'Runtime.consoleAPICalled': [Function],
'Page.javascriptDialogOpening': [Function],
'Runtime.exceptionThrown': [Function],
'Security.certificateError': [Function],
'Inspector.targetCrashed': [Function],
'Performance.metrics': [Function] },
_eventsCount: 16,
_maxListeners: undefined,
_lastId: 142,
_callbacks: Map {},
_connection:
Connection {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_url: 'ws://127.0.0.1:45941/devtools/browser/75a70228-1c06-43fc-b1db-4bcb31ea555a',
_lastId: 144,
_callbacks: Map {},
_delay: 0,
_ws: [WebSocket],
_sessions: [Map] },
_targetId: '(4A708DD8E19462D630BAE640E87EFE61)',
_sessionId: '(4A708DD8E19462D630BAE640E87EFE61):1' },
_page:
Page {
domain: null,
_events: { dialog: [AsyncFunction] },
_eventsCount: 1,
_maxListeners: undefined,
_client:
Session {
domain: null,
_events: [Object],
_eventsCount: 16,
_maxListeners: undefined,
_lastId: 142,
_callbacks: Map {},
_connection: [Connection],
_targetId: '(4A708DD8E19462D630BAE640E87EFE61)',
_sessionId: '(4A708DD8E19462D630BAE640E87EFE61):1' },
_keyboard: Keyboard { _client: [Session], _modifiers: 0, _pressedKeys: Set {} },
_mouse:
Mouse {
_client: [Session],
_keyboard: [Keyboard],
_x: 32.5,
_y: 652,
_button: 'none' },
_touchscreen: Touchscreen { _client: [Session], _keyboard: [Keyboard] },
_frameManager:
FrameManager {
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
_client: [Session],
_page: [Circular],
_frames: [Map],
_contextIdToContext: [Map],
_mainFrame: [Frame] },
_networkManager:
NetworkManager {
domain: null,
_events: [Object],
_eventsCount: 4,
_maxListeners: undefined,
_client: [Session],
_requestIdToRequest: [Map],
_interceptionIdToRequest: Map {},
_extraHTTPHeaders: {},
_offline: false,
_credentials: null,
_attemptedAuthentications: Set {},
_userRequestInterceptionEnabled: false,
_protocolRequestInterceptionEnabled: false,
_requestHashToRequestIds: [Multimap],
_requestHashToInterceptions: [Multimap] },
_emulationManager:
EmulationManager {
_client: [Session],
_emulatingMobile: true,
_injectedTouchScriptId: '1' },
_tracing: Tracing { _client: [Session], _recording: false, _path: '' },
_pageBindings: Map {},
_ignoreHTTPSErrors: false,
_screenshotTaskQueue: TaskQueue { _chain: [Promise] },
_viewport:
{ width: 375,
height: 667,
deviceScaleFactor: 2,
isMobile: true,
hasTouch: true,
isLandscape: false } },
_parentFrame:
Frame {
_client:
Session {
domain: null,
_events: [Object],
_eventsCount: 16,
_maxListeners: undefined,
_lastId: 142,
_callbacks: Map {},
_connection: [Connection],
_targetId: '(4A708DD8E19462D630BAE640E87EFE61)',
_sessionId: '(4A708DD8E19462D630BAE640E87EFE61):1' },
_page:
Page {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
_client: [Session],
_keyboard: [Keyboard],
_mouse: [Mouse],
_touchscreen: [Touchscreen],
_frameManager: [FrameManager],
_networkManager: [NetworkManager],
_emulationManager: [EmulationManager],
_tracing: [Tracing],
_pageBindings: Map {},
_ignoreHTTPSErrors: false,
_screenshotTaskQueue: [TaskQueue],
_viewport: [Object] },
_parentFrame: null,
_url: 'https://www.milanuncios.com/mis-anuncios/?pagina=1201',
_id: '(4A708DD8E19462D630BAE640E87EFE61)',
_context:
ExecutionContext {
_client: [Session],
_contextId: 16,
_objectHandleFactory: [Function: bound createJSHandle] },
_waitTasks: Set {},
_childFrames: Set { [Frame], [Frame], [Frame], [Circular] },
_name: undefined,
_loadingFailed: false },
_url: 'https://www.milanuncios.com/renovar/?id=245463427',
_id: '(6E766493375121224990C9457A8F3AF7)',
_context:
ExecutionContext {
_client:
Session {
domain: null,
_events: [Object],
_eventsCount: 16,
_maxListeners: undefined,
_lastId: 142,
_callbacks: Map {},
_connection: [Connection],
_targetId: '(4A708DD8E19462D630BAE640E87EFE61)',
_sessionId: '(4A708DD8E19462D630BAE640E87EFE61):1' },
_contextId: 55,
_objectHandleFactory: [Function: bound createJSHandle] },
_waitTasks: Set {},
_childFrames:
Set {
Frame {
_client: [Session],
_page: [Page],
_parentFrame: [Circular],
_url: 'https://vars.hotjar.com/rcj-99d43ead6bdf30da8ed5ffcb4f17100c.html',
_id: '(A8BF5BD0B465B80948EF2963DD0BA529)',
_context: [ExecutionContext],
_waitTasks: Set {},
_childFrames: Set {},
_name: '_hjRemoteVarsFrame',
_loadingFailed: false } },
_name: 'ifrw',
_loadingFailed: false } |
@fran0254 sure. So you had the following that works and want to get rid of timeout: await page.waitFor(2000); // <-- we want to get rid of this timeout!
const frame = page.frames().find(f => f.name() === 'ifrw'); // nit: no need to await
const button = await frame.$('#selector');
button.click(); For this, you can come up with a helper function function waitForFrame(page) {
let fulfill;
const promise = new Promise(x => fulfill = x);
checkFrame();
return promise;
function checkFrame() {
const frame = page.frames().find(f => f.name() === 'ifrw');
if (frame)
fulfill(frame);
else
page.once('frameattached', checkFrame);
}
} and use it later like this: // 1. waiting for frame with name 'ifrw' to get attached
const frame = await waitForFrame(page);
// 2. waiting for the frame to contain the necessary selector
await frame.waitForSelector('#selector');
const button = await frame.$('#selector');
button.click(); Note the step (2): iframe will be attached first and then navigated to its url, so we want to make sure the button exists before clicking. |
@aslushnikov The original posts mentioned knowing when a "frame is loaded". Is |
works perfect for me. Thank you |
Actually, I do not think that this solves the issue at hand: It should be possible to "waitUntil" a frame is loaded without watching for events. This would be a great addition to the functionality of the frame class and in consequence also for page. |
How to get the status of the iframe, as |
@jcppython you can track all requests using const requestPerFrame = new Map();
const page = await browser.newPage();
page.on('request', request => {
if (request.isNavigationRequest())
requestPerFrame.set(request.frame(), request);
});
await page.goto('https://example.com');
const someFrame = page.frames()[1];
const frameNavigationResponse = requestPerFrame.get(someFrame).response(); |
yes work
don´t work
The text was updated successfully, but these errors were encountered: