Can i set certain url to print from it without popup window (silent printing)?

Can i set certain url to print from it without popup window (silent printing)?

silent printing detect (window.print()) and print current window.
I need to pass url to this to print from it.

can i do that?

It might be possible by hooking into the printing XPCOM APIs, though it’s very unusual that you would want to start a hardware operation without any user input.

Whoops missed this topic.

Yes silent printing is possible. I use this technique when users disable the pref for “print preview - send direct to prienter on print”.

I was loading an image into a hidden iframe then printing that, but you can do the same with any browser element:

You can either use a framescript, or in my case my iframe is in process so I just tapped into contentWindow.print:
// print method link678321212
var win = Services.wm.getMostRecentWindow(‘navigator:browser’);
var doc = win.document;

        var iframe = doc.createElementNS(NS_HTML, 'iframe');
        iframe.addEventListener('load', function() {
            
            iframe.removeEventListener('load', arguments.callee, true);
            console.error('iframe loaded, print it', iframe.contentWindow.print);
            
            var gPostPrintRemovalFunc = function() {
                iframe.parentNode.removeChild(iframe);
                console.error('ok removed iframe that i added to hiddenDOMWindow')
                gPostPrintRemovalFunc = null;
            };
            
            iframe.contentWindow.addEventListener('afterprint', function() {
                // iframe.parentNode.removeChild(iframe);
                // console.error('ok removed iframe that i added to hiddenDOMWindow')
                // discontinued immediate removal as it messes up/deactivates print to file on ubuntu from my testing
                iframe.setAttribute('src', 'about:blank');
                
            }, false);
            
            iframe.contentWindow.print();
        }, true); // if i use false here it doesnt work
        
        
        iframe.setAttribute('src', this.myCanvasEl.toDataURL('image/png'));
        iframe.setAttribute('style', 'display:none');
        doc.documentElement.appendChild(iframe); // src page wont load until i append to document

Make sure to not destroy the browser element immediately after print, on Linux it causes weird errors.

Oh wait wait, my last solution does show the native print dialog. I think by silent you mean totally silent, so it should just print with default or last used options. Yeah that one I don’t know.

But if XPCOM fails you, you can do it in js-ctypes. Might be safer to go js-ctypes as XPCOM is definitely on the line to deprecation when servo comes out.