Skip to content

Instantly share code, notes, and snippets.

@salmin89
salmin89 / background.ts
Last active March 31, 2025 17:43
Extension Message Streaming Implementation
import { createElement } from 'react';
import { renderToReadableStream } from 'react-dom/server';
import Simple from '../components/Simple';
async function streamReactComponent(tabId) {
const stream = await renderToReadableStream(createElement(Simple));
// Initiate connection with content script
chrome.tabs.sendMessage(tabId, { type: 'START_REACT_STREAM' });
@salmin89
salmin89 / background.ts
Last active December 26, 2024 18:05
a wrapper for chrome.storage that allows for partial updates
(async () => {
await StorageLocal.set({ user1: { name: "Bob", age: 20 } });
await StorageLocal.get("user1").then((user) => {
console.log("get after set", user);
});
await StorageLocal.patch({ user1: { age: 21 } });
await StorageLocal.get("user1").then((user) => {
console.log("get after patch", user);
});
await StorageLocal.put({ user1: { name: "Updated" } });
@salmin89
salmin89 / action.ts
Created September 28, 2024 14:33
rxjs the communication flow between contentScript and background
export enum ActionType {
Add = 'add',
Remove = 'remove',
}
export type MessageStream = {
message: any;
sender: chrome.runtime.MessageSender;
sendResponse: (response?: any) => void;
};
@salmin89
salmin89 / background.ts
Last active September 27, 2024 15:25
sendMessage utill for browser extensions
import { Channel, makeChannel } from './myutil';
const { onMessage } = makeChannel(Channel.B);
onMessage((message, sender, callback) => {
callback('background response... B');
});
@salmin89
salmin89 / on-all.sh
Created April 4, 2022 19:23
shell scripts to perform commands on multiple repos at once
#usage oa -p /proj1/ -p /proj2/ git checkout master
while getopts "p:" flag; do
case $flag in
p) paths+=("$OPTARG");;
*) echo "Unexpected option ${flag}"; exit 1;;
esac
done
shift $(expr $OPTIND - 1 )
@salmin89
salmin89 / README.md
Last active April 22, 2020 18:20
Angular debugger

Descritpion:

An alternative to debug your Angular Component.

Installation

There are two ways of using this.

  1. Paste this code in the browser console
  2. Use a Javascript Compresser to minify it into a one-liner. Paste the code into the URL-part of a bookmark (javascript: code)

How to use

  • The first time you run the code, it'll ask you to enter the component name. Then it will save the component name in localStorage