Google Chrome Extension: Print the page silently - printing

I'm developing an internal Google Chrome Extension that needs a way to initiate print the current page to the printer. I do not want the default Print dialog to come up (so, javascript:window.print() is out of question).
As far as I understand, this is not possible just with the JS + HTML plug-in, so I'm also open to using the NPAPI plugin also (with a dummy mime-type). And I'm concerned for Windows platform only.
I'm also open for various hacks / workarounds if possible, though a standard solution would be nice.
If you think this is not possible, let me know if you know any feature request logged for it?
Any suggestions/clarifications are welcome..

In chrome (v18+) we have the --kiosk --kiosk-printing switches. One can print automatically to default printer without print confirmation.
You can see it from this video http://www.youtube.com/watch?v=D6UHjuvI7IE

Since NPAPI allows you to create native C++ plugins that you can interact with through an object tag (which you can use from an extension), that would probably be the way to do it.
The tricky bit is that I don't know of a good way to get the bits for printing the page. The only person I know of who has done something similar to this actually got the window handle for the browser (available through NPAPI) and scraped the bits off of it to print that way, but that won't take into account print stylesheets or anything. You could also try using automation events to try to control the print dialog, but I have no idea if that would work or not.
By design, the browsers try not to let you do something like this, as it could open some serious vulnerabilities if any website could just start printing things to your printer without confirmation...
Anyway, if you find a way to do it with C++ you can use FireBreath to ease the creation of the NPAPI plugin.

There are various extensions that take snapshots of the current web page (for example, this one); you could adapt one to send the image to a printer via an NPAPI plugin.

I've recently been looking for a similar ability, and it seems like it would be quite possible using Chrome's new native messaging api.
https://developer.chrome.com/extensions/nativeMessaging
There are plenty of examples of this with C#, but here is one quick example of troubleshooting Chrome native messaging with a basic C# application
Native messaging from chrome extension to native host written in C#
I realize this may be a day late and a dollar short, but in case anyone else comes across this question, this is the solution that worked for me. From inside a C# app, you can directly print to installed printers using the PrintDocument class. If you figured out a way to get the page image, this would be far easier than using firebreath or NPAPI.

Disable print preview in Google Chrome on Mac
Quit Google Chrome
Launch Terminal on your Mac. (Search “Terminal” using the Search box)
Type defaults write com.google.Chrome DisablePrintPreview -bool true
Close Terminal and open Google Chrome
Disable print preview in Google Chrome on Windows
Close Google Chrome
From your desktop, right click Google Chrome
Click Properties
In the dialog box, add ‘ –disable-print-preview‘ at the end of the Target field sans the apostrophe (make sure to include the space before –)
Click Apply
Disable print preview in Firefox on Mac
In the address bar type “about:config” and press Enter.
Right click on the page, hover over ‘New’ and click on ‘Boolean’
Type ‘print.always_print_silent’ as the preference name and click ‘OK’
Click on ‘true’ and click ‘OK’.
Close the about:config window.
Disable print preview in Firefox on Windows
In the address bar type “about:config” and press Enter.
Right click on the page, hover over ‘New’ and click on ‘Boolean’ Type
‘print.always_print_silent‘ as the preference name and click ‘OK’
Click on ‘true’ and click ‘OK’.
Close the about:config window.
https://support.dryfta.com/how-to-disable-print-preview-in-chrome-firefox-on-windows-mac/

Related

How I can see the console.log messages

How I can see the displayed messages for application running using console.log see below image example:
Additional data: I am running on WebLogic Server and I am using webssh, is a web application that I run using runtime of Java and open it in Internet Explorer.
Sample code of console.log:
You need to open the tools of internet explore from toolbar and select developer tools or you can press F12.
Then after you can see the inspection bar, right side of inspection bar has console.
I think you can see that message at there.
Developer tools are pretty powerful in every browser. Today we almost have a consensus on hotkeys.
Rigth click on the viewport then you will see inspect elements then a rectangular box will show up with many tabs and the second one is the console where you can see all of the console.log()

How to have a Firefox Devtools inspector like feature for Firefox addons?

For ex: I want to see which parts of the html code correspond to a specific element of a website, I would right-click on the element and open inspect element and devtools would show me the corresponding code highlighted. How do I achieve a similar result for Firefox addons because when I right click on the extension there's no such option of inspect element.
I have also tried to use the inspect option which we get by temporarily loading an addon but still it doesn't show us/highlight which parts of the extension the corresponding html file refer to.
Is there a way to do so?
In current versions of Firefox, inspecting and debugging add-ons works by opening the Add-ons Manager, clicking the gear icon at the top and choosing Debug Add-ons or by going to about:debugging#/runtime/this-firefox.
In there you'll get a list of all installed add-ons. And you can debug them by clicking on the Inspect button besides them.
This opens up a new DevTools window just for that specific add-on. So you can inspect and debug them.
In older versions of Firefox, debugging add-ons is a bit more cumbersome.
Depending on the type of extension, it is possible to inspect their contents using the Browser Toolbox.
This feature first needs to be enabled by switching to the DevTools' Settings panel and enabling the two options Enable browser chrome and add-on debugging toolboxes and Enable remote debugging.
Once they are enabled, you can open the Browser Toolbox via the Firefox Menu > Web Developer > Browser Toolbox or by pressing Ctrl+Alt+Shift+I or Cmd+Opt+Shift+I on Mac.
This toolbox has an Inspector like the normal DevTools, which allows you to inspect the browser chrome.
Having said that, the Inspector obviously can't inspect documents placed in nested <browser> elements, which is the case for extensions to the DevTools themselves, for example.

Is there a way to bypass Chrome geolocation dialog in Protractor tests?

I faced this problem, when automating an application with protractor.
Once I open a home page I get geolocation dialog with Block/Allow buttons, which didn't let proceed without selection either option
It turned out, that this dialog is not an instance of alert, that's why browser.switchTo().alert().confirm() didn't work
Passing '--disable-notifications' argument to Chrome also didn't solve the problem
Research online didn't give any positive results. How to solve it?
The solution to the problem is to pass "prefs": {'profile.default_content_setting_values.geolocation': 2} to capabilities object in your protractor.config.js
Below is another option that does pretty much the same thing.
So chrome may take an argument --user-data-dir=/tmp/chrome which specifies profile to open chrome with. If profile doesn’t exist at specified directory it creates default one.
Then if you open /tmp/chrome/Default/Preferences you’ll see an object with preferences. You needed to set default_content_setting_values.geolocation to 2 (not 1 or 0) to make it NOT prompt that dialog

Find features of a non Microsoft program

I'm not sure how to even ask this question, but let's say I have a program such as Google Chrome. How would I find out the "features" of it so I can use PowerShell to modify it.
For example, how would I have Chrome open a web page and click a button.
I know for IE, you can use $ie.document.getElementById("loginform").submit() to click a button.
Thank you,
Tony
You can't ever really get the same amount of control over non-Windows programs using Powershell.
In terms of Chrome, you could simply open the browser and go to a webpage with:
$Start-Process "chrome.exe" "www.google.com"
There is generally not that much more for further functionality, but with Chrome you may be able to do things like change settings and configuration. Check out the (large) JSON file Preferences and other config files, which you can find in Chrome's local appdata folder (Win+R, %localappdata%, Google/Chrome/User Data/Default). I'm not too sure but it may also be a bad idea to mess around with these files.
I also did a Google search and found this third party powershell tool for browsers, called Selenium. Here's the list of extensions.

Cross browser addons

This has been discussed in a few threads - but none gave any real answers.
I need to develop a very simple browser addon which just has a single button, and can run a javascript function when pressed. It must sit as a toolbar or similair.
Now, is there an easy way to develop once for Chrome, IE, and FF?
Only supporting the latest version of each browser is fine too.
Thanks
If you mean a javascript (not particular to a certain browser e.g showing the history) you can run it like this (pasting it into the url bar):
javascript:alert("Hello!");
You can make a link with the href going to your script, then tell your users to drag the link into their bookmarks bar. E.g
Link text

Resources