Skip to content

Instantly share code, notes, and snippets.

View dotproto's full-sized avatar

Simeon Vincent dotproto

View GitHub Profile
@dotproto
dotproto / background.js
Created April 12, 2022 20:40
Double click action in Manifest V3. Heavily based on Turn Off the Lights.
let alreadyClicked = false;
let timer;
chrome.action.onClicked.addListener(function(tab) {
let wasClicked = alreadyClicked;
// Reset state
if (wasClicked) {
clearTimeout(timer);
alreadyClicked = false;
@dotproto
dotproto / gist:8f0b3e39215f002a0908be3d3122ce88
Last active March 29, 2022 21:52
Calculate pixel height in inches/mm at a given distance
/**
* @param {number} srcPixels Number of pixels used when rendering on a standard desktop dispaly. Defaults to 1 pixel
* @param {number} distance Distance in inches at which the item is rendered. Defaults to 28 inches (distance specified in the CSS spec)
*
* https://www.w3.org/TR/css-values-4/#reference-pixel
*/
function getProjectedPixel({pixels = 1, distance = 28} = {}) {
const inToMm = (inch) => inch * 25.4;
const opposite = distance;
@dotproto
dotproto / devtools.html
Created September 8, 2021 03:33
DevTools network request monitor. Minimal demo to show how one could use `chrome.devtools.network.onRequestFinished` to monitor request traffic on a given page.
<!DOCTYPE html>
<script src="devtools.js"></script>
@dotproto
dotproto / index.html
Created September 7, 2021 17:20
Test: Spawn a WebWorker inside a service worker. This test was created to verify whether or not standard web workers can be instantiated from within a service worker.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>Web Workers basic example</title>
</head>
<body>
<script src="main.js"></script>
@dotproto
dotproto / background.js
Last active May 5, 2023 02:20
Inject video on page that has a CSP restrict that would normally prevent the video from being injected. To see this demo in action, load the extension unpacked and trigger the extension's action on the desired page.
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
let videos = [
{
url: 'https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4',
type: 'video/mp4',
}, {
url: 'https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm',
type: 'video/webm',
@dotproto
dotproto / index.html
Created August 13, 2021 03:38
Include 3rd party images/images in a Manifest V3 extension page
<!--
Copyright 2021 Google LLC.
SPDX-License-Identifier: Apache-2.0
-->
<video width="320" height="240" controls
preload="none" playsinline="" aria-label="Stephen Colbert Popcorn Munching GIF"
disablepictureinpicture="" poster="https://pbs.twimg.com/tweet_video_thumb/E8o7fA9VoAojxVl.jpg"
src="https://video.twimg.com/tweet_video/E8o7fA9VoAojxVl.mp4" type="video/mp4"></video>
@dotproto
dotproto / background.js
Created July 23, 2021 18:14
Manifest V3 module service worker demo
// Copyright 2021 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
// Use importScripts to load other JS files
import { demo } from './lib.js';
console.log(demo.greeting);
@dotproto
dotproto / background.js
Created July 23, 2021 18:04
Manifest V3 importScripts try/catch demo
// Copyright 2021 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
// Use importScripts to load other JS files
importScripts('./lib.js');
console.log(self.demo.greeting);
@dotproto
dotproto / background.js
Created January 11, 2021 23:37
Basic example of requesting optional broad host permissions
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
chrome.runtime.onInstalled.addListener(({reason}) => {
console.log(reason);
console.log(chrome.runtime.OnInstalledReason.UPDATE);
if (reason === chrome.runtime.OnInstalledReason.INSTALL ||
reason === chrome.runtime.OnInstalledReason.UPDATE) {
chrome.tabs.create({url: 'popup.html'});
@dotproto
dotproto / LICENSE
Last active July 16, 2020 14:09
MV3 webRequest demo. To view the console, you may need to manually open devtools for the service worker. On Chrome, visit chrome://serviceworker-internals and search for the service worker registered to `chrome-extension://<extension-id>/` where extension-id is the ID of your extension.
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,