question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot switch context to Chrome Custom Tab

See original GitHub issue

The problem

We are unable to switch Context to the Chrome Custom Tab context.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.15.1
  • Last Appium version that did not exhibit the issue (if applicable): -
  • Desktop OS/version used to run Appium: macOS Catalina
  • Node.js version (unless using Appium.app|exe):
  • Npm or Yarn package manager:
  • Mobile platform/version under test: Android 9
  • Real device or emulator/simulator: Real
  • Appium CLI or Appium.app|exe: Appium.app

Details

When our Chrome Custom Tab is displayed, we cannot switch context to it. This means we are unable to automate our login page. We get the following error message:

>>> driver.switch_to.context(driver.contexts[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/appium/webdriver/switch_to.py", line 30, in context
    self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name})
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/appium/webdriver/errorhandler.py", line 29, in check_response
    raise wde
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/appium/webdriver/errorhandler.py", line 24, in check_response
    super(MobileErrorHandler, self).check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get sockets matching: @webview_devtools_remote_.*16060
  (make sure the app has its WebView configured for debugging)

Link to Appium logs

https://gist.github.com/roddymunro/1778d2a0c98d1eddb5b0d52225d64dd8

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
KazuCocoacommented, May 29, 2021

As https://github.com/appium/appium/issues/13543#issuecomment-846686776 , basic custom tabs work at least 1.21.0.

1reaction
KazuCocoacommented, May 24, 2021

I tested the custom tab with https://github.com/GoogleChrome/android-browser-helper/tree/main/demos/custom-tabs-example-app . Then, it worked like the below. (Emulator and developers option enabled to debug chrome browser). So, it seems to work for now. (At least, I tested the repository with Appium 1.21.0 and current master) (Possibly older version may require chromeOptions and androidPackage to handle chrome package name)

https://gist.github.com/KazuCocoa/708fc5f297e5d60cf9862f930ddcabd2

[5] pry(#<AppiumLibCoreTest::DriverTest>)> @driver = @@core.start_driver
=> #<Appium::Core::Base::Driver:0xc7f7de9e752e902 browser="unknown">
[6] pry(#<AppiumLibCoreTest::DriverTest>)> @driver.available_contexts
=> ["NATIVE_APP", "WEBVIEW_chrome"]
[7] pry(#<AppiumLibCoreTest::DriverTest>)> @driver.context = 'WEBVIEW_chrome'
=> "WEBVIEW_chrome"
[8] pry(#<AppiumLibCoreTest::DriverTest>)> @driver.title
=> "Android Developers"

According to https://developer.chrome.com/docs/android/custom-tabs/integration-guide/ , the chrome package name can be different in beta and stable. Then, probably it requires to set "chromeOptions": { "androidPackage": "com.android.beta" } for example.

appium:enableWebviewDetailsCollection: true may also need. (This was not needed on my environment though)


What’s the result of https://github.com/appium/appium-uiautomator2-driver#mobile-getcontexts in your case? It may print all available chrome tabs on the device via chrome://inspect/#devices. It should help to investigate your case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome Custom Tabs change the default close button not ...
I was originally trying to use the svg icons. When I changed to png it started working. Not sure why the svg doesn't...
Read more >
Chrome Custom Tabs | CodePath Android Cliffnotes
Chrome custom tabs allow an app to customize how Chrome looks and feels. An app can change things like: Toolbar color; Enter and...
Read more >
Android Custom Tabs implementation guide
The first step for a Custom Tabs integration is adding the AndroidX Browser Library to your project. Open the app/build.gradle file and add ......
Read more >
Use Chrome Custom Tabs they said, it will be fun they said
The issue with the browser is that there is a context switch. Every time the user would open a url in the phones...
Read more >
Chrome Custom Tabs Android Studio - YouTube
Your browser can't play this video. Learn more. Switch camera.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found