pryscraper/browser-extension/background.js
cryptorugmunch 8d25702eca chore(license): re-license to dual MIT (core) + BSL 1.1 (stealth)
Squashed from chore/license-relicense. Full message preserved in the
original branch commit bb77eb5. See ADR-0002 for the decision rationale.

Refs: ADR-0002, commit bb77eb5
2026-07-02 19:59:18 +02:00

35 lines
1.1 KiB
JavaScript

// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Rug Munch Media LLC
// Part of Pry — https://git.rugmunch.io/RugMunchMedia/pryscraper
// Licensed under MIT. See LICENSE.
// Pry Browser Extension — Background Service Worker
chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.get(['pryServerUrl'], function(result) {
if (!result.pryServerUrl) {
chrome.storage.sync.set({pryServerUrl: 'http://localhost:8002'});
}
});
});
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.type === 'scrape') {
scrapeUrl(message.url, message.config).then(sendResponse);
return true;
}
});
async function scrapeUrl(url, config) {
try {
const response = await fetch(config.serverUrl + '/v1/scrape', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(config.apiKey ? {'Authorization': 'Bearer ' + config.apiKey} : {})
},
body: JSON.stringify({url: url, bypassCloudflare: true})
});
return await response.json();
} catch (err) {
return {success: false, error: err.message};
}
}