-
-
Notifications
You must be signed in to change notification settings - Fork 150
How to download or show PDF #457
Replies: 1 comment · 4 replies
-
Hey! Do you have CDP log? What version are you on? |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you so much for your quick answer. 🙌 I don't have a CDP log and I didn't even know that there's a dedicated log. The versions are cuprite (0.15)
ferrum (0.14) |
Beta Was this translation helpful? Give feedback.
All reactions
-
Got it, yea you can run one test in particular prefixing rspec command with |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Hello @route, I hope that you're able to see more in that log than I do. 😆 The test is quite long but this is the log after clicking the link:
|
Beta Was this translation helpful? Give feedback.
All reactions
-
I think this is Chrome bug and here's minimal reproducible example: require 'bundler/inline'
gemfile do
gem 'cuprite', path: "../"
gem 'ferrum', path: '../ferrum'
gem "rspec", "~> 3.10"
gem "sinatra", "~> 3.2"
gem "puma", ">= 5.6.7"
end
require "rack/handler/puma"
require "sinatra/base"
class Application < Sinatra::Base
set :root, File.dirname(__FILE__)
set :static, true
set :raise_errors, true
set :show_exceptions, false
get "/" do
%(Hello world! <a href="/attachment.pdf">Download PDF</a>)
end
get "/attachment.pdf" do
attachment("attachment.pdf")
send_file("#{File.dirname(File.expand_path(__FILE__))}/attachment.pdf")
end
end
class Server
attr_reader :host, :port
def initialize(host: "127.0.0.1", port: 31337)
@host = host
@port = port
@app = Application.new
@server_thread = nil
end
def boot!
@server_thread = Thread.new { run }
end
private
def run
options = { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }
config = Rack::Handler::Puma.config(@app, options)
log_writer = config.options[:Silent] ? ::Puma::LogWriter.strings : ::Puma::LogWriter.stdio
config.options[:log_writer] = log_writer
log_writer.log "Starting Puma"
log_writer.log "* Version #{Puma::Const::PUMA_VERSION} , codename: #{Puma::Const::CODE_NAME}"
log_writer.log "* Min threads: #{config.options[:min_threads]}, max threads: #{config.options[:max_threads]}"
Puma::Server.new(config.app, nil, config.options).tap do |s|
s.binder.parse(config.options[:binds], log_writer)
s.min_threads = config.options[:min_threads] if s.respond_to?(:min_threads=)
s.max_threads = config.options[:max_threads] if s.respond_to?(:max_threads=)
end.run.join
end
end
server = Server.new
server.boot!
sleep 2
browser = Ferrum::Browser.new
page = browser.create_page
page.go "http://127.0.0.1:31337/"
page.downloads.set_behavior(save_path: "/tmp", behavior: :allow)
page.at_xpath("//a[@href]").click
puts page.downloads.files Try adding target to the link. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @route,
long time no see.
I am migrating an old project to Cuprite/Ferrum and this project tackles PDF often.
Somehow I seem to miss an important bit so maybe you have an idea.
I added a helper that should force PDF to be downloaded (I got this code from your comment):
And I can see the
puts
statement for pretty much all the requests before but not for the request of the PDF.Could it be because the PDF is opened in a new window (
<a href="..." target="_blank" ...
)? Or any other reason?If I am disabling the headless mode, I can see that the PDF URL is opened in a new tab and shows this error message:
It probably makes no difference but the PDF is opened via
first(:xpath, ...).click
which then opens the new tab.Also I saw that in Selenium there's an plugin option called
plugins.always_open_pdf_externally
.Can this be used here with Ferrum/Cuprite too?
Beta Was this translation helpful? Give feedback.
All reactions