JBrowser Source Docs

jbrowser.engine.signin

Generated from the source code of JBrowser 2.0.3.

jbrowser/engine/signin.py · 180 lines

Signing in to Google: the space presents Firefox while one of its pages is on the sign-in server.

Google refuses to sign in browsers it takes for web views embedded in other apps ("Couldn't sign you in. This browser or app may not be secure"). Sending a Firefox user agent to accounts.google.com only (services/privacy.py, since 1.5.1) is enough on most PCs. Where Google looks closer, it also sees the rest of the page still saying Chromium (navigator.userAgent, navigator.userAgentData and the Sec-CH-UA headers) and refuses anyway; switching DevTools' user agent to Firefox fixed it.

So while any page of a space (a card or a sign-in popup) is on Google's sign-in server, the space's profile presents Firefox everywhere a site can look (identity.apply_firefox), and a few seconds after the last one leaves it goes back to Chrome. The switch happens before the navigation is sent, so the sign-in page itself loads with the consistent identity.

Where even that fails, "Fix and sign in again" (TabController._offer_signin_fix) presents Firefox to every site until the sign-in has worked: signedIn fires once Google has handed out its session cookies and the last sign-in page has been left, and ProfileManager then goes back to Chrome.

Constants#

Name Value
SIGNIN_HOST re.compile('^accounts\\.(?:google\\.[a-z]{2,3}(?:\\.[a-z]{2})?|youtube\\.com)$')
RESTORE_DELAY_MS 12000
RENAVIGATE_GAP 30.0
SESSION_COOKIES {b'SID', b'__Secure-1PSID', b'__Secure-3PSID', b'SAPISID'}
SUCCESS_PATH re.compile('/(?:accounts/)?(?:SetSID|CheckCookie)\\b', re.IGNORECASE)

SigninIdentity#

class SigninIdentity(QObject)source
SigninIdentity(restore: Callable[[QWebEngineProfile], None], parent: QObject | None=None, always_firefox: Callable[[], bool]=lambda: False)

Keeps track of which pages are on a sign-in server and switches their profiles' identity.

Signals

Signal Arguments
signedIn ()

SigninIdentity.is_firefox#

is_firefox(profile: QWebEngineProfile) -> boolsource

SigninIdentity.watch#

watch(page: QWebEnginePage) -> Nonesource

SigninIdentity.before_navigation#

before_navigation(page: QWebEnginePage, url: QUrl, is_main: bool) -> boolsource

Called from acceptNavigationRequest (also for redirects), before the request is sent. Returns False when the navigation has to wait: Chromium can't change a page's identity from inside that callback, so the space switches to Firefox a moment later and then the page loads url again. Google never sees a request from the half-switched browser.

on_cookie(profile: QWebEngineProfile, cookie: QNetworkCookie) -> Nonesource

Every cookie a profile receives (cheap check). Google's session cookies arriving while one of the profile's pages is signing in mean the sign-in worked. (Cookies loaded from disk at start-up don't count: no page is signing in then.)

SigninIdentity.forget_profile#

forget_profile(profile: QWebEngineProfile) -> Nonesource

The profile is going away (its space was closed).

Functions#

is_signin_url#

is_signin_url(url: QUrl) -> boolsource

is_rejection_url#

is_rejection_url(url: QUrl) -> boolsource

Google's "Couldn't sign you in. This browser or app may not be secure" page.

is_success_url#

is_success_url(url: QUrl) -> boolsource
is_session_cookie(cookie: QNetworkCookie) -> boolsource