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

feat: add custom debugging port option #173

Merged
merged 1 commit into from Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppeteer/launcher/chrome.rb
Expand Up @@ -34,7 +34,7 @@ def launch(options = {})
if @launch_options.pipe?
chrome_arguments << '--remote-debugging-pipe'
else
chrome_arguments << '--remote-debugging-port=0'
chrome_arguments << "--remote-debugging-port=#{@chrome_arg_options.debugging_port}"
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/puppeteer/launcher/chrome_arg_options.rb
Expand Up @@ -34,9 +34,10 @@ def initialize(options)
if @headless.nil?
@headless = !@devtools
end
@debugging_port = options[:debugging_port] || 0
end

attr_reader :args, :user_data_dir
attr_reader :args, :user_data_dir, :debugging_port

def headless?
@headless
Expand Down
2 changes: 1 addition & 1 deletion lib/puppeteer/launcher/firefox.rb
Expand Up @@ -28,7 +28,7 @@ def launch(options = {})
end

if firefox_arguments.none? { |arg| arg.start_with?('--remote-debugging-') }
firefox_arguments << '--remote-debugging-port=0'
firefox_arguments << "--remote-debugging-port=#{@chrome_arg_options.debugging_port}"
end

temporary_user_data_dir = nil
Expand Down
2 changes: 2 additions & 0 deletions lib/puppeteer/puppeteer.rb
Expand Up @@ -44,6 +44,7 @@ def launch(
args: nil,
user_data_dir: nil,
devtools: nil,
debugging_port: nil,
headless: nil,
ignore_https_errors: nil,
default_viewport: NoViewport.new,
Expand All @@ -63,6 +64,7 @@ def launch(
args: args,
user_data_dir: user_data_dir,
devtools: devtools,
debugging_port: debugging_port,
headless: headless,
ignore_https_errors: ignore_https_errors,
default_viewport: default_viewport,
Expand Down
10 changes: 10 additions & 0 deletions spec/integration/launcher_spec.rb
Expand Up @@ -260,6 +260,16 @@
expect(screenshot.size).to be > 50000
end
end

it 'should set the debugging port' do
options = default_launch_options.merge(
debugging_port: 9999,
)

Puppeteer.launch(**options) do |browser|
expect(URI(browser.ws_endpoint).port).to eq(9999)
end
end
end

describe 'Puppeteer#default_args', puppeteer: :browser do
Expand Down