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

MHTML screenshots #285

Open
AlexWayfer opened this issue Jul 7, 2021 · 2 comments
Open

MHTML screenshots #285

AlexWayfer opened this issue Jul 7, 2021 · 2 comments

Comments

@AlexWayfer
Copy link

As you wrote in the README:

Better looking HTML screenshots

By the default, HTML screenshots will not look very good when opened in a browser. This happens because the browser can't correctly resolve relative paths like <link href="/assets/...." />, which stops CSS, images, etc... from being loaded. To get a nicer looking page, configure Capybara with:

Capybara.asset_host = 'http://localhost:3000'

This will cause Capybara to add <base>http://localhost:3000</base> to the HTML file, which gives the browser enough information to resolve relative paths. Next, start a rails server in development mode, on port 3000, to respond to requests for assets:

rails s -p 3000

Now when you open the page, you should have something that looks much better. You can leave this setup in place and use the default HTML pages when you don't care about the presentation, or start the rails server when you need something better looking.

It's understandable, but not the best solution for each case, especially for CI (like GitHub Actions) with artifacts.


So, my suggestion is to make MHTML screenshots. Chrome supports it (you can try, it's wonderful!), maybe some other drivers (browsers) too.

@TylerRick
Copy link
Contributor

Ooh, nice idea! I use .mhtml files all the time when saving web pages from a browser (so that they're self contained and contain all the assets they need).

It does seem like they could potentially help with this problem too...

@TylerRick
Copy link
Contributor

Just noticed that ferrum has built-in support for saving as .mhtml (https://github.com/rubycdp/ferrum#mhtmloptions--string--integer). 👀 ❗

Not sure other drivers do, though (I doubt it). But I may play around with Cuprite/Ferrum now that I know it exists...

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

No branches or pull requests

2 participants