frostman
frostman
PD🧩 Plasmo Developers
Created by frostman on 5/2/2024 in #👟framework
How to adjust the with-firebase-auth to work with Arc (other chromium browsers)
Solved it from the background script like this, works for all Chromium browsers that I have tested:
import type { PlasmoMessaging } from "@plasmohq/messaging"
import {
GoogleAuthProvider,
signInWithCredential,
signOut,
} from "firebase/auth";
import { app, auth } from "~firebase";

const handleSignIn = async (request, sender) => {
try {
const redirectUri = chrome.identity.getRedirectURL();
const clientId = process.env.PLASMO_PUBLIC_FIREBASE_CLIENT_ID
const authUrl = `https://accounts.google.com/o/oauth2/auth?client_id=${clientId}&response_type=token&redirect_uri=${encodeURIComponent(redirectUri)}&scope=email openid profile`;

return new Promise((resolve, reject) => {
chrome.identity.launchWebAuthFlow({
url: authUrl,
interactive: true,
}, (redirectUrl) => {
if (chrome.runtime.lastError || !redirectUrl) {
reject(new Error("WebAuthFlow failed: " + chrome.runtime.lastError.message));
return;
}
const params = new URLSearchParams(new URL(redirectUrl).hash.substring(1));
const accessToken = params.get('access_token');
const credential = GoogleAuthProvider.credential(null, accessToken);

signInWithCredential(auth, credential).then((userCredential) => {
resolve(userCredential.user);
}).catch((error) => {
reject(new Error("Firebase signInWithCredential failed: " + error.message));
});
});
});
} catch (e) {
throw new Error("Sign-in failed: " + e.message);
}
};


const handleSignOut = async (request, sender) => {
try {
await signOut(auth);
return "Signed out successfully.";
} catch (e) {
throw new Error("Sign-out failed: " + e.message);
}
};

const getUser = async (request, sender) => {
return auth.currentUser;
}
import type { PlasmoMessaging } from "@plasmohq/messaging"
import {
GoogleAuthProvider,
signInWithCredential,
signOut,
} from "firebase/auth";
import { app, auth } from "~firebase";

const handleSignIn = async (request, sender) => {
try {
const redirectUri = chrome.identity.getRedirectURL();
const clientId = process.env.PLASMO_PUBLIC_FIREBASE_CLIENT_ID
const authUrl = `https://accounts.google.com/o/oauth2/auth?client_id=${clientId}&response_type=token&redirect_uri=${encodeURIComponent(redirectUri)}&scope=email openid profile`;

return new Promise((resolve, reject) => {
chrome.identity.launchWebAuthFlow({
url: authUrl,
interactive: true,
}, (redirectUrl) => {
if (chrome.runtime.lastError || !redirectUrl) {
reject(new Error("WebAuthFlow failed: " + chrome.runtime.lastError.message));
return;
}
const params = new URLSearchParams(new URL(redirectUrl).hash.substring(1));
const accessToken = params.get('access_token');
const credential = GoogleAuthProvider.credential(null, accessToken);

signInWithCredential(auth, credential).then((userCredential) => {
resolve(userCredential.user);
}).catch((error) => {
reject(new Error("Firebase signInWithCredential failed: " + error.message));
});
});
});
} catch (e) {
throw new Error("Sign-in failed: " + e.message);
}
};


const handleSignOut = async (request, sender) => {
try {
await signOut(auth);
return "Signed out successfully.";
} catch (e) {
throw new Error("Sign-out failed: " + e.message);
}
};

const getUser = async (request, sender) => {
return auth.currentUser;
}
3 replies
PD🧩 Plasmo Developers
Created by frostman on 2/9/2024 in #👟framework
Pin Side Panel like google search
No description
5 replies
PD🧩 Plasmo Developers
Created by frostman on 2/9/2024 in #👟framework
Pin Side Panel like google search
Now when Chrome 123 > have disabled that side panel button, how can i get that functionality back? Would be insainly helpful to get that back. Or just be able to trigger it in another way.
5 replies
PD🧩 Plasmo Developers
Created by frostman on 2/9/2024 in #👟framework
Pin Side Panel like google search
Bump this, anyone that knows if it possible?
5 replies
PD🧩 Plasmo Developers
Created by frostman on 2/16/2024 in #👾extension
How can i show an welcome page when users install my extension?
I was able to do it via the BG script like this: chrome.runtime.onInstalled.addListener(function (details) { console.log("onInstalled", details); if (details.reason == "install") { let url = chrome.runtime.getURL("tabs/index.html"); chrome.tabs.create({ url: url }); } });
3 replies