Skip to content

Commit

Permalink
complement pour la gestion de l'iframe print
Browse files Browse the repository at this point in the history
  • Loading branch information
Refhi committed Jan 4, 2024
1 parent f09c381 commit 9a9e39f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
30 changes: 20 additions & 10 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

});
}
});
Expand Down
14 changes: 8 additions & 6 deletions keyCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});
}
},
Expand Down

0 comments on commit 9a9e39f

Please sign in to comment.