1

I've followed Getting the source HTML of the current page from Chrome extension to get HTML source from current page, and I modified the chrome.runtime.onMessage.addListener function like this:

chrome.runtime.onMessage.addListener(function(request, sender) {
    if (request.action == "getSource") {
        message.innerText = request.source;
        //my code
        window.print();
    }
});

But window.print() does not work, can you please help me correct it?

Thank you very much for any help you can provide!

Community
  • 1
  • 1
dung ta van
  • 988
  • 8
  • 13
  • In which file are you invoking print? It must be within the content script, not the background task. – sdgluck Dec 14 '15 at 14:59

2 Answers2

0

Your code is reversed for print. Change "print.window()" to the following:

window.print();
Mike Horstmann
  • 580
  • 2
  • 9
-1

You need a timeout before calling print.

You may use the code snippet as work around: window.print(); setTimeout(function(){window.close();}, 10000); //give them 10 seconds to print, then close

For your reference, please follow the link below: Print function in Chrome no longer working

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30