(Why) does Chromote open two Chrome windows by default?
Closed this issue · 3 comments
bersbersbers commented
> b <- chromote::ChromoteSession$new()
> b$Browser$getWindowBounds(1)
$bounds
$bounds$left
[1] 0
$bounds$top
[1] 0
$bounds$width
[1] 800
$bounds$height
[1] 600
$bounds$windowState
[1] "normal"
> b$Browser$getWindowBounds(2)
$bounds
$bounds$left
[1] 0
$bounds$top
[1] 0
$bounds$width
[1] 992
$bounds$height
[1] 1323
$bounds$windowState
[1] "normal"
> b$Browser$getWindowBounds(3)
Error in onRejected(reason) : code: -32000
message: Browser window not found
bersbersbers commented
It sure looks like it:
> b <- chromote::ChromoteSession$new()
> b$Target$getTargets()
$targetInfos
$targetInfos[[1]]
$targetInfos[[1]]$targetId
[1] "9F366095DEA57A0DC74273262A14FD03"
$targetInfos[[1]]$type
[1] "page"
$targetInfos[[1]]$title
[1] "about:blank"
$targetInfos[[1]]$url
[1] "about:blank"
$targetInfos[[1]]$attached
[1] TRUE
$targetInfos[[1]]$canAccessOpener
[1] FALSE
$targetInfos[[1]]$browserContextId
[1] "BDFA500459C76683F235CF173AC8477B"
$targetInfos[[2]]
$targetInfos[[2]]$targetId
[1] "294530650069700B65A13ED0F8F8111F"
$targetInfos[[2]]$type
[1] "page"
$targetInfos[[2]]$title
[1] "about:blank"
$targetInfos[[2]]$url
[1] "about:blank"
$targetInfos[[2]]$attached
[1] FALSE
$targetInfos[[2]]$canAccessOpener
[1] FALSE
$targetInfos[[2]]$browserContextId
[1] "BDFA500459C76683F235CF173AC8477B"
wch commented
It's because ChromoteSession$new()
starts a Chrome instance (if not already started), and when Chrome starts, it has a tab/window open. Then ChromoteSession$new()
tells Chrome to open a new tab.
It may be possible to start the first ChromoteSession
with the unused tab.
hadley commented
I now only see a single target:
sess <- chromote::ChromoteSession$new()
str(sess$Target$getTargetInfo())
#> List of 1
#> $ targetInfo:List of 7
#> ..$ targetId : chr "C9EA14C1F3262AC457388DA7B7473BA6"
#> ..$ type : chr "page"
#> ..$ title : chr "about:blank"
#> ..$ url : chr "about:blank"
#> ..$ attached : logi TRUE
#> ..$ canAccessOpener : logi FALSE
#> ..$ browserContextId: chr "3666C1F98B71B8B00FAC95CFAA4DF4AD"
Created on 2024-01-30 with reprex v2.0.2.9000