Skip to content

Instantly share code, notes, and snippets.

Avatar

Simeon Vincent dotproto

View GitHub Profile
@dotproto
dotproto / background.js
Created Apr 12, 2022
Double click action in Manifest V3. Heavily based on Turn Off the Lights.
View background.js
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 Mar 29, 2022
Calculate pixel height in inches/mm at a given distance
View gist:8f0b3e39215f002a0908be3d3122ce88
/**
* @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 Sep 8, 2021
DevTools network request monitor. Minimal demo to show how one could use `chrome.devtools.network.onRequestFinished` to monitor request traffic on a given page.
View devtools.html
<!DOCTYPE html>
<script src="devtools.js"></script>
@dotproto
dotproto / index.html
Created Sep 7, 2021
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.
View index.html
<!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 Aug 24, 2021
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.
View background.js
// 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 Aug 13, 2021
Include 3rd party images/images in a Manifest V3 extension page
View index.html
<!--
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 Jul 23, 2021
Manifest V3 module service worker demo
View background.js
// 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 Jul 23, 2021
Manifest V3 importScripts try/catch demo
View background.js
// 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 Jan 11, 2021
Basic example of requesting optional broad host permissions
View background.js
// 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 Jul 16, 2020
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.
View LICENSE
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,