From 9a9e39f5baf4f37fc8c6e5edd1c0b6aa4eb6532b Mon Sep 17 00:00:00 2001 From: Refhi Date: Thu, 4 Jan 2024 21:56:26 +0100 Subject: [PATCH] complement pour la gestion de l'iframe print --- content.js | 30 ++++++++++++++++++++---------- keyCommands.js | 14 ++++++++------ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/content.js b/content.js index 1c03c0e..0361c41 100644 --- a/content.js +++ b/content.js @@ -224,16 +224,26 @@ function sendPrint() { console.log('iframe', iframe); // Obtenez l'URL du document dans l'iframe - let url = iframe.contentWindow.location.href; - console.log('url', url); - - // Utilisez l'URL dans une requête fetch - fetch(iframe.contentWindow.location.href) - .then(response => response.blob()) - .then(blob => { - sendToCompanion(`http://localhost:${portCompanion}/print?apiKey=${apiKey}`, blob); - }) - .catch(error => console.error('Error:', error)); + let intervalId = setInterval(() => { + url = iframe.contentWindow.location.href; + console.log('url', url); + + if (url !== 'about:blank') { + clearInterval(intervalId); + fetch(iframe.contentWindow.location.href) + .then(response => response.blob()) + .then(blob => { + sendToCompanion(`http://localhost:${portCompanion}/print?apiKey=${apiKey}`, blob); + }) + .catch(error => console.error('Error:', error)); + + } + }, 100); + + setTimeout(() => { + clearInterval(intervalId); + }, 5000); + }); } }); diff --git a/keyCommands.js b/keyCommands.js index 0edc9e5..293611a 100644 --- a/keyCommands.js +++ b/keyCommands.js @@ -218,12 +218,14 @@ const keyCommands = { clickFirstPrinter(); waitForElement('iframe', null, 5000, function (iframe) { console.log('iframe détecté:', iframe); - if (RemoveLocalCompanionPrint) { - iframe.contentWindow.print(); - } - else { - sendPrint(); - } + chrome.storage.local.get(['RemoveLocalCompanionPrint'], function (result) { + if (result.RemoveLocalCompanionPrint) { + iframe.contentWindow.print(); + } + else { + sendPrint(); + } + }); }); } },