updated
This commit is contained in:
@@ -1,28 +1,48 @@
|
||||
/**
|
||||
* Quality Label Printing Service - Content Script
|
||||
* Injects print service functionality into web pages
|
||||
* Simplified injection for extension ID detection
|
||||
*/
|
||||
|
||||
console.log('Quality Label Printing - Content Script Loaded');
|
||||
|
||||
// Inject extension ID into the page as a hidden DOM element for detection
|
||||
// Inject extension ID into DOM for web page detection
|
||||
function injectExtensionId() {
|
||||
try {
|
||||
const existing = document.getElementById('chrome-extension-id');
|
||||
if (existing) return; // Already injected
|
||||
const el = document.createElement('div');
|
||||
el.id = 'chrome-extension-id';
|
||||
el.setAttribute('data-extension-id', chrome.runtime.id);
|
||||
el.style.display = 'none';
|
||||
document.documentElement.appendChild(el);
|
||||
// Optionally, also set a global variable
|
||||
window.CHROME_EXTENSION_ID = chrome.runtime.id;
|
||||
console.log('Injected extension ID:', chrome.runtime.id);
|
||||
} catch (e) {
|
||||
console.warn('Failed to inject extension ID:', e);
|
||||
// Remove any existing extension ID element
|
||||
const existingElement = document.getElementById('chrome-extension-id');
|
||||
if (existingElement) {
|
||||
existingElement.remove();
|
||||
}
|
||||
|
||||
// Create new element with extension ID
|
||||
const extensionIdElement = document.createElement('div');
|
||||
extensionIdElement.id = 'chrome-extension-id';
|
||||
extensionIdElement.setAttribute('data-extension-id', chrome.runtime.id);
|
||||
extensionIdElement.style.display = 'none';
|
||||
|
||||
// Add to document head or body
|
||||
(document.head || document.body || document.documentElement).appendChild(extensionIdElement);
|
||||
|
||||
console.log('Extension ID injected:', chrome.runtime.id);
|
||||
}
|
||||
injectExtensionId();
|
||||
|
||||
console.log('Quality Label Printing Service: Content script loaded');
|
||||
// Inject extension ID when DOM is ready
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', injectExtensionId);
|
||||
} else {
|
||||
injectExtensionId();
|
||||
}
|
||||
|
||||
// Remove all script injection and messaging. Only inject the extension ID for CSP compatibility.
|
||||
// Also inject when page changes (for SPAs)
|
||||
if (window.navigation) {
|
||||
navigation.addEventListener('navigate', injectExtensionId);
|
||||
} else {
|
||||
// Fallback for older browsers
|
||||
let lastUrl = location.href;
|
||||
new MutationObserver(() => {
|
||||
const url = location.href;
|
||||
if (url !== lastUrl) {
|
||||
lastUrl = url;
|
||||
setTimeout(injectExtensionId, 100);
|
||||
}
|
||||
}).observe(document, { subtree: true, childList: true });
|
||||
}
|
||||
Reference in New Issue
Block a user