Add product scanning functionality to eBay extension
- Introduced a new scanProductsForAccount feature in the background script to handle product scanning requests. - Implemented a timeout mechanism for scan requests to enhance reliability. - Updated content scripts to parse product lists and extract relevant data from eBay storefronts. - Enhanced error handling and logging for better debugging and user feedback. - Added methods to extract items sold and shop names from eBay profiles.
This commit is contained in:
@@ -3,20 +3,62 @@
|
||||
|
||||
const MESSAGE_SOURCE = "eship-webapp";
|
||||
|
||||
// Markiere Extension als verfügbar
|
||||
// #region agent log
|
||||
try {
|
||||
console.log('[ESHIP-CONTENT] Content script loaded');
|
||||
if (typeof window !== 'undefined') {
|
||||
window.__EBAY_EXTENSION__ = true;
|
||||
console.log('[ESHIP-CONTENT] window.__EBAY_EXTENSION__ set to true');
|
||||
} else {
|
||||
console.error('[ESHIP-CONTENT] window is undefined!');
|
||||
// Markiere Extension als verfügbar - MEHRFACH versuchen, da Timing variieren kann
|
||||
function setExtensionFlag() {
|
||||
try {
|
||||
const hasChrome = typeof chrome !== 'undefined';
|
||||
const hasRuntime = hasChrome && chrome.runtime;
|
||||
const runtimeId = hasRuntime ? chrome.runtime.id : null;
|
||||
if (typeof window !== 'undefined' && hasChrome && hasRuntime && runtimeId) {
|
||||
window.__EBAY_EXTENSION__ = true;
|
||||
window.__EBAY_EXTENSION_ID__ = runtimeId; // Extension-ID für chrome.runtime.sendMessage
|
||||
console.log('[ESHIP-CONTENT] window.__EBAY_EXTENSION__ set to true, ID:', runtimeId);
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[ESHIP-CONTENT] Error setting flag:', e);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[ESHIP-CONTENT] Error setting flag:', e);
|
||||
return false;
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// Versuche Flag sofort zu setzen
|
||||
console.log('[ESHIP-CONTENT] Content script loaded');
|
||||
if (!setExtensionFlag()) {
|
||||
// Wenn window nicht verfügbar, warte auf DOMContentLoaded oder document.readyState
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
setExtensionFlag();
|
||||
});
|
||||
} else {
|
||||
// DOM ist bereits geladen, versuche nochmal
|
||||
setTimeout(() => {
|
||||
setExtensionFlag();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Sende Extension-ID an Web-App via postMessage (da Content Script Isolation verhindert, dass window-Properties geteilt werden)
|
||||
// Die Web-App kann dann die Extension-ID in ihrem eigenen Context speichern
|
||||
function sendExtensionIdToWebApp() {
|
||||
try {
|
||||
const runtimeId = chrome.runtime?.id;
|
||||
if (runtimeId) {
|
||||
// Sende Extension-ID an Web-App
|
||||
window.postMessage({
|
||||
source: "eship-extension",
|
||||
type: "EXTENSION_ID",
|
||||
extensionId: runtimeId
|
||||
}, "*");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[ESHIP-CONTENT] Error sending extension ID:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Sende Extension-ID beim Laden
|
||||
sendExtensionIdToWebApp();
|
||||
// Auch nach kurzer Verzögerung nochmal (falls Web-App noch nicht bereit ist)
|
||||
setTimeout(sendExtensionIdToWebApp, 500);
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
// Sicherheitscheck: Nur Nachrichten von derselben Origin akzeptieren
|
||||
|
||||
Reference in New Issue
Block a user