Print page content - google-chrome-app

I just started playing with google chrome apps. I've searched the internet and haven't found the way to print the content of the windows. Tried using windows.print(), but nothing happened.
As far as I have read, the print() wont work since it is called in the background.html that does not have any content. How can I make the call at the correct place and send the content of the app to the printer?
Thank you in advance!

You're right that this can't be done through the Background page, since it is not rendered. What you'll need to do is inject a "content script" into the page you would like to print. The content script would contain the print command, and probably whatever would trigger the print command.
In a nutshell, "content scripts" are scripts that are injected into the pages a user browses. You can inject pretty much any JavaScript you like, and even inject entire JavaScript libraries like JQuery. More details can be found here:
https://developer.chrome.com/extensions/content_scripts.html
If you decide to use a popup window to trigger the print you can pass a message to the window you would like to print. Message passing is how the different components of an extension (background page, content script, popup) communicate. More info can be found here:
http://developer.chrome.com/extensions/messaging.html

Printing in apps is not yet supported, I believe. See
Issue 131279: async version of window.print()

Related

Silent printing on clients printer for a hospital front desk ADF project

I am working on a Hospital front desk ADF project, here I need to generate visit slips these dont require print preview.I want to get to print the slips without any print dialogs nor do I want a popup window. I tried lot of stuff found on the net but nothing solid has come up..
Tried this.print on the Jasper report, tried the same through Java but I am getting dialog.
I am working on an intranet so the security aspect is out of the discussion so how so I make this work?
This is a suggestion rather than an answer, but I can't write comments before I get 50 points of reputation (thank you for the warm welcome, StackOverflow!) - maybe one of these will help:
1) Printing an html file using java without showing print dialog to the user
2) How would I suppress the print dialog in this example?
I was able to perform the silent print, I used a popup window to call a servlet which generated the required visit slip and displayd the same on the pop window. For the silent print I used
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print({bUI: false,bSilent: false,bShrinkToFit: true,printParams:this.getPrintParams().constants.interactionLevel.silent});this.close();");
I had to make a couple of changes to IE, I added my url to the trusted site option in IE. I enabled js in acrobat and also pointed acrobat to the trusted sites in IE. This resolved silent print but am stuck with another issue..
I am not being able to close the window once print is done.. I tried this..
"var win = window.open('PrintPopUp.jsf','_blank',\"height=300,width=200,scrollbars=no," +
"status=no, resizable=no, screenx=0, screeny=0\");win.onclick=function(){setTimeout(function(){win.close();\n},9000);}
But its not working in IE 11.. any suggestions?
Well I found out a way to do this..
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT,
"var pp = this.getPrintParams();pp.interactive=pp.constants.interactionLevel.silent;pp.NumCopies=1; this.disclosed= true ;this.print({bUI: false,bSilent: false,bShrinkToFit: true,printParams:pp});");
This adds pdf javascript to the generated pdf..
Once the pdf is displayed on the popup page it performs the silent print.. Hope this helps someone in the future..

Handling pop ups using selenium with perl

I want a solution for the following scenario:
In a page I am uploading an xml and while clicking on the upload button I am going to recieve an pop up for confirmation (I am able to detect this), after this again I am recieving an pop up which I am not able to detect (The page is still getting loaded in the browser ). Kindly help me to sort this out .
I have tried with many solutions for this like: get window ids,titles .
Thanks
You can you use -
$sel->get_confirmation()
This retrieves the message of a JavaScript confirmation dialog generated duringthe previous action. By default, the confirm function will return true, having the same effectas manually clicking OK. This can be changed by prior execution of thechooseCancelOnNextConfirmation command. If an confirmation is generatedbut you do not get/verify it, the next Selenium action will fail.
NOTE: under Selenium, JavaScript confirmations will NOT pop up a visibledialog.
NOTE: Selenium does NOT support JavaScript confirmations that aregenerated in a page's onload() event handler. In this case a visibledialog WILL be generated and Selenium will hang until you manually clickOK.
Returns the message of the most recent JavaScript confirmation dialog.
You should always refer to WWW::Selenium - Perl Client while working with perl and RC.
I have found what is the problem #amey ...I am tring to upload an file which is not actually not permitted due to some security issues with firefox... There was actually an work around for this
http://cakebaker.42dh.com/2006/03/29/file-upload-with-selenium/
.....Which will not work with latest Selenium RC with Firefox since firefox have removed the support for enablePrivilege
https://support.mozilla.org/en-US/questions/944433.
So it is a mandate to shift to WEBDRIVER it seems.............
http://git.erp5.org/gitweb/erp5.git/commitdiff/06898bbfae4f238b7e79ce05048646529216064e
Thanks for your support....
my solution was using the function:
$driver->execute_script("Events.invokeEvent('UserDetailPage:UserDetailScreen:UserDetailToolbarButtonSet:UserDetailToolbarButtons_DeleteUserButton_act', true);");
analyzing what the javascript code does when the Accept button was pressed. and executing that code in the function.

Can't see dynamically loaded code in Chrome Developer Tools 22

When I dynamically load a snippet of html containing javascript via AJAX, I cannot see that content in the source tab in the developer tools window in Chrome 22.0.1229.94. Tellingly, I went here
https://developers.google.com/chrome-developer-tools/docs/scripts-breakpoints#js_dynamic
This page shows an example developer tools window which is out of date. There is a button on the page to load a dynamic script and it does not show up in the source tab when you do.
As a work-around, I have found that adding
debugger;
to the script and reloading it will cause it to pause in the dynamically loaded code, but unfortunately, all the line numbers are greyed out and you can't set any breakpoints within the debugger.
Am I missing something here or what?
Thanks,
Rob
When you use a library or javascript code that you have loaded it dynamically, you can use the phrase
//# sourceURL=foo.js
at the beginning of your javascript code that foo.js is the name that will be assigned it. debugger will show it with that name.
This is true in chrome, and I think in firebug too.
In this case you can place a breakpoint in the dynamically loaded javascript code.
Possible duplicate of:
Is possible to debug dynamic loading JavaScript by some debugger like WebKit, FireBug or IE8 Developer Tool?
Don't know if this works or not in chrome (This definitely doesn't work for me now, may be in the past).
//# sourceURL=foo.js
Working Solution
For your dynamically loaded script via ajax to appear in your chrome source tool, you need to add the following line at the start or end (I prefer) location of your script file:
//# sourceURL=foo.js
And your script with name foo.js will appear at the left pane of source tab under (no domain) dropdown
->localhost
-- source/src
->(no domain)
-- foo.js
Alternatively you can add the below line in your script anywhere between the scripts.
debugger;
In chrome, you can use " debugger; " statement to break at a statement when debugger panel is open. Chrome will simply ignore this if the debugger panel is closed.
This will help stop your script in debugging mode and you will see your script in source (debugging) panel with name like VM****.
Hope this helps.
You can use //# sourceURL. Chrome doesn't seem to be supporting //# sourceURL for inline scripts. However, it does work on eval expressions. This article gives more details about naming eval blocks and naming of any anonymous functions in your code.
Instead of using eval, you can try embedding a script tag or JSONP may be.
Varunkumar Nagarajan
for me it happened on nodejs project.
i restarted server and open in new tab my app and tada!..
Alternatively, to fix this problem you can open developer tool in a seprate window by clicking the icon. Now reload your script, and it will shown in script tab as expected. I know this is not a solution but a work arround.

Flash wmode="direct" issue on FB canvas app

I develop a FB app using Flash using wmode="direct" (for 3D graphics).
In Internet Explorer, every time I popup any FB dialog (e.g Purchase Credits dialog), the flash disappears and when the dialog is closed, the flash does not re-appear...
I tried to set the visibility after dialog is closed:
http://developers.facebook.com/docs/appsonfacebook/tutorial/ (under "Special Considerations for Adobe Flash developers"), but it didn't work.
I've also tried the use FB.Init hideFlashCallback:
http://developers.facebook.com/blog/post/555/ (under "Detecting visibility of Flash objects in Canvas apps"), but it doesn't seem to call the callback function...
Any one had the same issue and manage to make it work?
Any other suggestions?
P.S - I use swfobject to embed the SWF file.
Thank a lot!
Roei
UPDATE: I removed the appId param from the FB JS url:
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#appId=XXXX&xfbml=1"></script>
and now the hideFlashCallback is executed, but still - the flash does not re-appear...
I've updated the section Special Considerations for Adobe Flash developers because the code snippet was a bit out-of-date.
The new snippet should give you an idea of how to use the hideFlashCallback, whose semantics have changed since that now out-of-date blog post, in that the function now takes a flash element as an argument. (Unfortunately, we haven't redocumented it yet, but will soon). One thing to note is that the callback does not currently work on IE8, but will after a fix gets pushed next Tuesday.
That said, it should work without that callback. It may be caused by a javascript fatal that stops script execution before the re-showing happens. Look in your javascript console to see if you see any errors.
Otherwise, if you can give me the canvas URL for your application, I can look into it.
Did you try it with other wmodes? what you can try is actually remove the div where you write your flash to, add it with innerHTML and run the swfobject.embed again

How to read message from console tab view in eclipse plugin development

requirement is to read message from IConsoleConstants.ID_CONSOLE_VIEW and write it into text file.
Say myConsole (of type MessageConsole) is the reference to your console. The below code will give you the required.
myConsole.getDocument().get();
I don't think you will be able to retreive a direct stream to read the console content. Note also that the console view may have multiple different consoles, you will have to retrieve the good one.
Retrieving the content displayed in a single console should be possible going through the IDocument of a TextConsole. You can get the whole text content. You could also have a look to the IDocumentListener if you can be notified of changes.
Another solution should be to go with a PatternMatchListener of the TextConsole directly.
Anyway I don't think there is a direct solution to do this with the Eclipse console API.