Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ browser.runtime.onInstalled.addListener(async ({reason}) => {

// GitHub Enterprise support
addDomainPermissionToggle();

// `background` fetch required to avoid avoid CORB introduced in Chrome 73 https://chromestatus.com/feature/5629709824032768
// Don’t turn this into an `async` function https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage#addListener_syntax
browser.runtime.onMessage.addListener(({request}): Promise<Response> | void => {
return fetch(request).then(async response => response.json());
});
9 changes: 2 additions & 7 deletions source/features/embed-gist-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';
import {isFirefox} from '../github-helpers';

const isGist = (link: HTMLAnchorElement): boolean =>
!link.pathname.includes('.') && // Exclude links to embed files
Expand All @@ -20,8 +19,8 @@ async function embedGist(link: HTMLAnchorElement): Promise<void> {
link.after(info);

try {
const response = await fetch(`${link.href}.json`);
const gistData = await response.json();
// Get the gist via background.js due to CORB policies introduced in Chrome 73
const gistData = await browser.runtime.sendMessage({request: `${link.href}.json`});

const files = domify.one(gistData.div)!;
const fileCount = files.children.length;
Expand Down Expand Up @@ -60,9 +59,5 @@ void features.add({
include: [
pageDetect.hasComments
],
exclude: [
// https://github.com/sindresorhus/refined-github/issues/2022
() => isFirefox
],
init
});