OpenBullet2 icon indicating copy to clipboard operation
OpenBullet2 copied to clipboard

[Bug]: PuppeteerSwitchToTab does not switch to the selected index

Open timolarra opened this issue 2 years ago • 2 comments

Version of the software

0.2.4

Operating system

Windows 10

Browser / Native

Chrome 105.0.5195.127

What happened?

As mentioned in the title, PuppeteerSwitchToTab does not switch to the selected index. For example, if you have 5 Tabs open in your browser, and you want to move to Tab 2, PuppeteerSwitchToTab will give you another tab instead.

Despite opening this issue a year ago, it has not been resolved https://github.com/openbullet/OpenBullet2/issues/269

Relevant LoliCode if needed

No response

timolarra avatar Sep 25 '22 20:09 timolarra

Are you sure it's not 0-indexed? Tab index 0 should be the first tab, then index 1 should be the second one and so on. Can you check?

openbullet avatar Oct 07 '22 06:10 openbullet

Yes I am sure of that, just try to open 3 or 4 tabs and switch to tab 2 or 3 and you will see what will happen

timolarra avatar Oct 09 '22 18:10 timolarra

After some debugging, I found this issue on the PuppeteerSharp repository, which suggests a workaround.

I added some additional logging to the RuriLib block after implementing the workaround and it seems to work as expected now.

// LoliCode
BLOCK:PuppeteerOpenBrowser
ENDBLOCK

BLOCK:PuppeteerNavigateTo
ENDBLOCK

BLOCK:PuppeteerGetAttributeValue
  findBy = Selector
  identifier = "title"
  => VAR @puppeteerGetAttributeValueOutput
ENDBLOCK

BLOCK:PuppeteerNewTab
ENDBLOCK

BLOCK:PuppeteerNewTab
ENDBLOCK

BLOCK:PuppeteerNewTab
ENDBLOCK

BLOCK:PuppeteerNewTab
ENDBLOCK

BLOCK:PuppeteerSwitchToTab
  index = 2
ENDBLOCK

BLOCK:PuppeteerNavigateTo
  url = "https://picsum.photos/200/300"
ENDBLOCK

BLOCK:PuppeteerSwitchToTab
  index = 3
ENDBLOCK

BLOCK:PuppeteerNavigateTo
  url = "https://picsum.photos/200/300"
ENDBLOCK

BLOCK:PuppeteerSwitchToTab
  index = 1
ENDBLOCK

BLOCK:PuppeteerNavigateTo
  url = "https://picsum.photos/200/300"
ENDBLOCK

BLOCK:PuppeteerSwitchToTab
  index = 4
ENDBLOCK

BLOCK:PuppeteerNavigateTo
  url = "https://picsum.photos/200/300"
ENDBLOCK
// Output
>> Open Browser (PuppeteerOpenBrowser) << 
Browser opened successfully! 
>> Navigate To (PuppeteerNavigateTo) << 
Navigated to https://example.com 
Tab 0: https://example.com/ 
>> Get Attribute Value (PuppeteerGetAttributeValue) << 
Got value Example Domain of attribute innerText by executing document.querySelectorAll('title')[0].innerText; 
Assigned value to variable 'puppeteerGetAttributeValueOutput' 
>> New Tab (PuppeteerNewTab) << 
Opened a new page 
>> New Tab (PuppeteerNewTab) << 
Opened a new page 
>> New Tab (PuppeteerNewTab) << 
Opened a new page 
>> New Tab (PuppeteerNewTab) << 
Opened a new page 
>> Switch to Tab (PuppeteerSwitchToTab) << 
Switched to tab with index 2 
>> Navigate To (PuppeteerNavigateTo) << 
Navigated to https://picsum.photos/200/300 
Tab 0: https://example.com/ 
Tab 1: about:blank 
Tab 2: https://fastly.picsum.photos/id/299/200/300.jpg?hmac=iJwKPn_sm8S_ZGJttTHq5EpwaEESy8Q-qDaQ9xWtlYw 
Tab 3: about:blank 
Tab 4: about:blank 
>> Switch to Tab (PuppeteerSwitchToTab) << 
Switched to tab with index 3 
>> Navigate To (PuppeteerNavigateTo) << 
Navigated to https://picsum.photos/200/300 
Tab 0: https://example.com/ 
Tab 1: about:blank 
Tab 2: https://fastly.picsum.photos/id/299/200/300.jpg?hmac=iJwKPn_sm8S_ZGJttTHq5EpwaEESy8Q-qDaQ9xWtlYw 
Tab 3: https://fastly.picsum.photos/id/721/200/300.jpg?hmac=6g_vLTUju_TGWN7cMKTjZgzqps-JjmHIS0KSuFsgVyc 
Tab 4: about:blank 
>> Switch to Tab (PuppeteerSwitchToTab) << 
Switched to tab with index 1 
>> Navigate To (PuppeteerNavigateTo) << 
Navigated to https://picsum.photos/200/300 
Tab 0: https://example.com/ 
Tab 1: https://fastly.picsum.photos/id/643/200/300.jpg?hmac=rS-MHa0BIMHdAgm-FZ7QM36aRKEAzzhSRNRv5n4uqGc 
Tab 2: https://fastly.picsum.photos/id/299/200/300.jpg?hmac=iJwKPn_sm8S_ZGJttTHq5EpwaEESy8Q-qDaQ9xWtlYw 
Tab 3: https://fastly.picsum.photos/id/721/200/300.jpg?hmac=6g_vLTUju_TGWN7cMKTjZgzqps-JjmHIS0KSuFsgVyc 
Tab 4: about:blank 
>> Switch to Tab (PuppeteerSwitchToTab) << 
Switched to tab with index 4 
>> Navigate To (PuppeteerNavigateTo) << 
Navigated to https://picsum.photos/200/300 
Tab 0: https://example.com/ 
Tab 1: https://fastly.picsum.photos/id/643/200/300.jpg?hmac=rS-MHa0BIMHdAgm-FZ7QM36aRKEAzzhSRNRv5n4uqGc 
Tab 2: https://fastly.picsum.photos/id/299/200/300.jpg?hmac=iJwKPn_sm8S_ZGJttTHq5EpwaEESy8Q-qDaQ9xWtlYw 
Tab 3: https://fastly.picsum.photos/id/721/200/300.jpg?hmac=6g_vLTUju_TGWN7cMKTjZgzqps-JjmHIS0KSuFsgVyc 
Tab 4: https://fastly.picsum.photos/id/160/200/300.jpg?hmac=RM8ofyEQBOl_xUcD4r_IVw6CQeVY8AQ4qtdM8js1D18 

So I think I will just implement the workaround for now.

openbullet avatar Jul 06 '24 12:07 openbullet