Skip to content

Commit

Permalink
Merge pull request #520 from touhidurrr/custom-user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
jmerle authored Nov 15, 2024
2 parents ba59b30 + fff20b3 commit 188e7e7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Runtime } from 'webextension-polyfill';
import { version } from '../../package.json';
import { Message, MessageAction } from '../models/messaging';
import { browser } from './browser';
import { sendToBackground } from './messaging';
Expand All @@ -11,10 +12,15 @@ export const requiredPermissions: Record<string, string> = {
'https://judge.beecrowd.com/': 'https://resources.beecrowd.com/*',
};

const defaultHeaders = {
'X-Competitive-Companion': version,
} as const;

/**
* Fetches a URL using a GET request and resolves into the HTML body.
*/
export async function request(url: string, options: RequestInit = {}, retries: number = 3): Promise<string> {
options.headers = { ...defaultHeaders, ...options.headers };
const response = await fetch(url, { credentials: 'include', ...options });

if (response.ok && response.status === 200) {
Expand Down

0 comments on commit 188e7e7

Please sign in to comment.