Comments (8)
You need to set the width/height using a command line option. Unfortunately, this is dependent on the operating system (and I'm not sure if this is going to change for the headless version, either).
Basically, you pass a runner option to chromedp.New():
ctxt, cancel := context.WithCancel(context.Background());
defer cancel()
c, err := chromedp.New(ctxt, chromedp.WithRunnerOptions(runner.WindowSize(width, height)))
from chromedp.
BTW, in the future I do plan to be able to prove some way to resize the window dynamically, but the issue with that is that currently Chrome (as far as I can tell) does not support that via the Remote Debugging Protocol, and I would need to write cross-platform support to resize the window via either system calls or via some other mechanism, and I just don't have the bandwidth at the moment to do the research needed. Also, as this is geared mostly towards running remote chrome instances, it wouldn't work when you're running chrome that way.
from chromedp.
There has to be some way, how else would you emulate mobile?
I found
metrics := emulation.SetDeviceMetricsOverride(1024, 4068, 0, false, false)
// set the device metrics
if err := c.Run(ctxt, metrics); err != nil {
log.Fatal(err)
}
Which didn't set the actual device though. I've also noticed if you try to issue a "Click" on a button that's not within the window's view, it can't click it and dies.
from chromedp.
The rendering and events of Chrome are completely dependent on the items being in view, which, yes, I know, is a giant pain. You need to scroll to the element first (ie, via javascript) before applying an action against something. I am in the process of overhauling the existing actions to take this into account. With headless chrome, this may not be necessary. I am definitely not an expert with the Chrome API yet, but I also had tried the emulation domain to override settings, and it did not do what I had hoped.
from chromedp.
How would you go about scrolling to the element?
from chromedp.
I was able to get further with:
vp := emulation.ForceViewport(1920, 1080, 1.0)
metrics := emulation.SetDeviceMetricsOverride(1920, 1080, 1, false, false)
if err = c.Run(ctxt, vp); err != nil {
log.Fatal(err)
}
if err = c.Run(ctxt, metrics); err != nil {
log.Fatal(err)
}
It seems like it's able to interact with buttons that would be out of the window, but it's now within the view port. The downfall is that the page is gray. I was able to get the page to render by pressing "F12 (dev tools)".
from chromedp.
https://groups.google.com/a/chromium.org/forum/#!topic/headless-dev/qcvOjVUZ-WQ
This seems to talk about it. From what I can tell, the buffer thinks it's that size, but the window might not actually be the size (that's why we see gray). So in theory, this is working, it's just not viewable.
from chromedp.
I have a big fix rollup that I'll be pushing either late today or early tomorrow, that should fix the issues for elements that are off screen.
Basically, a "Click" action actually becomes a composition of the following:
- Get dimensions (DOM.getBoxModel) of content
- window.scrollTo() to the element's location via Runtime.evaluate
- DOM.focus()
- Input.dispatchMouseEvent with button down / up
From my simple testing so far, this seems to work 100% of the time -- I'm not going to try to claim it's 100% perfect, but I haven't found any failure scenarios yet.
from chromedp.
Related Issues (20)
- Navigate Hangup with custom url scheme HOT 1
- page.StopLoading() cannot stop navigate
- chrome failed to start with no detail error
- Screenshot from remote browser
- context canceled even with new context HOT 1
- Download events being omitted on the page level but chromedp listens for it on the Browser level HOT 1
- Image not showing up in header
- Can't use proxy and open multiple tabs ?
- Target.targetCrashed > errorCode 11 with chromedp.Navigate() in Docker container environnement HOT 7
- Is it possible to use the net/http client in chromedp ? HOT 1
- GetOuterHTML().WithPierce(true) not returning <iframe> contents
- How to execute JavaScript in a specified context? HOT 1
- How to set the state of ShadowDOM from closed to open?
- Question: condition for set FooterTemplate
- Is it possible to capture error messages related to CORS, CSP violations, mixed-content violations, etc.?
- Can I Capture Raw HTTP Data?
- How to start chrome in arm environment?Are there any other plans?
- Why can't I listen to my iframe's network requests
- How i get dpi of chrome
- Import cookie using json
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 chromedp.