Skip to content

Commit

Permalink
Merge pull request #173 from YusukeIwaki/porting/4993
Browse files Browse the repository at this point in the history
feat: add custom debugging port option
  • Loading branch information
Yusuke Iwaki committed Dec 4, 2021
2 parents d3481e5 + c81f2af commit 786b7f2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
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

0 comments on commit 786b7f2

Please sign in to comment.