Squashed from chore/license-relicense. Full message preserved in the original branch commitbb77eb5. See ADR-0002 for the decision rationale. Refs: ADR-0002, commitbb77eb5
35 lines
1.1 KiB
JavaScript
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};
|
|
}
|
|
}
|