Wait for reflow or render to finish after applying style
See original GitHub issueHow should I wait for the re-render to occur after I apply a style to a div? Is there any event for this?
Or else I am getting an error of Error: Could not compute box model.
when calling DOM.getBoxModel()
right after applying a style.
const CDP = require('chrome-remote-interface');
const chromeLauncher = require('chrome-launcher');
chromeLauncher.launch({
port: 9222,
chromeFlags: [
'--disable-gpu',
'--headless',
],
}).then(async (chrome) => {
const client = await CDP({ port: chrome.port });
client.on('error', (err) => {
console.error(err);
});
const { Page, DOM, CSS } = client;
await Page.enable();
await Page.navigate({
url: 'http://github.com',
});
await Page.loadEventFired();
await DOM.enable();
await CSS.enable();
const { root: { nodeId: docNodeId } } = await DOM.getDocument();
const { nodeId: formId } = await DOM.querySelector({
nodeId: docNodeId,
selector: 'form[action="/join"]',
});
await CSS.setEffectivePropertyValueForNode({
nodeId: formId,
propertyName: 'display',
value: 'none',
});
await CSS.setEffectivePropertyValueForNode({
nodeId: formId,
propertyName: 'display',
value: 'block',
});
// Here the above code applies the style
// but doesn't wait for the render to finish.
await DOM.getBoxModel({ nodeId: formId });
// So after this line it is throwing an error saying
// Could not compute box model
client.close();
chrome.kill();
}).catch((err) => {
console.error(err);
});
Component | Version |
---|---|
Operating system | OSX 10.12.6 |
Node.js | v8.2.1 |
Chrome Canary | v62.0.3187.0 |
chrome-remote-interface | v0.24.3 |
Is Chrome running in a container? NO
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to properly wait for browser reflow/repaint to finish
Let's say I have a complex HTML component that I want to animate, but every time it needs to be animated, several things...
Read more >Understanding Repaint and Reflow in JavaScript | The Startup
parts of the render tree (or the whole tree) will need to be revalidated and the node dimensions recalculated. This is called a...
Read more >Avoid Reflow & Repaint - Hi Masterclass #7 - YouTube
Are you ready to find out more about how to "Avoid Reflow & Repaint"? Your well-known Masterclass expert Pedro Oliveira will guide you ......
Read more >How to wait for the browser to finishing reflow in javascript?
HTML : How to wait for the browser to finishing reflow in javascript? [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] ...
Read more >Preventing Content Reflow From Lazy-Loaded Images
Reflow is a problem because it's a user-blocking operation. It slows down the browser by forcing it to recalculate the layout of any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d wait for two sequential requestAnimationFrame()s to fire. then you can be sure these changes have applied.
It’s not a huge deal IMO but i would just hardcode the 2 nested raf inside a single runtime.evaluate…
roughly like