android-browser-helper
android-browser-helper copied to clipboard
WebView Fallback not working google sign-in
When authorizing in the console, the error
Scripts may close only the windows that were opened by them
demo: https://github.com/GoogleChrome/android-browser-helper/tree/master/demos/twa-webview-fallback
- os: chrome os 86.0.4217.0
- android-browser-helper 1.3.2
index.html
<b></b>
<button id="authorize_button" style="display: none;">Authorize</button>
<button id="signout_button" style="display: none;">Sign Out</button>
<script type="text/javascript">
const
uname = document.querySelector('b'),
authorizeButton = document.getElementById('authorize_button'),
signoutButton = document.getElementById('signout_button');
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
function initClient() {
gapi.client.init({
apiKey: '<YOUR_API_KEY>',
clientId: '<YOUR_CLIENT_ID>',
scope: 'email profile'
}).then(function () {
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
updateSigninStatus();
authorizeButton.onclick = () => gapi.auth2.getAuthInstance().signIn();
signoutButton.onclick = () => gapi.auth2.getAuthInstance().signOut();
}, err => alert(JSON.stringify(err, null, 2)));
}
function updateSigninStatus() {
if (gapi.auth2.getAuthInstance().isSignedIn.get()) {
const profile = gapi.auth2.getAuthInstance().currentUser.get().getBasicProfile();
uname.innerText = 'Name: '+profile.getName();
authorizeButton.style.display = 'none';
signoutButton.style.display = 'block';
}else{
uname.innerText = '';
authorizeButton.style.display = 'block';
signoutButton.style.display = 'none';
}
}
</script>
<script async defer
src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()"
></script>