window.print() is not working in chrome 77 version - google-chrome

I am facing one issue since my chrome browser is updated to version 77.
Initially window.print() is working fine, but once I open a page where it includes embedded PDF using <embed> tag, window.print() stopped working. Using Ctrl+P shortcut it opens the print popup but when I execute window.print() in javascript it doesn't work.
I have executed window.print() command in console, it directly returns undefined.
There might be a some changes in Chrome 77 release as per this thread https://support.google.com/chrome/thread/14107571?hl=en
Does any one have face this issue ?
Please help.

Looks like this is related to Chrome settings issues, because turning off chrome://flags/#mime-handler-view-in-cross-process-frame fixing that issue.
For someone that did not know how to turn off that, please do this:
Open new tab on chrome, and type chrome://flags/
You will have Experiments page opened.
Then type: Mime on the search bar on that page.
That will show you: MimeHandlerView in cross-process frame
Change that value from: Default to: Disabled, then it will ask you to relaunch the chrome.
After the chrome restarted, the printing function will work fine.

I am facing some what similar issue - once the pdf file is rendered, by the chrome pdf viewer, the window.print() starts returning undefined.
More detailed description - A pdf file is rendered into the tab, user hits back and then print() stops working. It is important that all is executed in the same tab.

$(document).ready(function () {
var URL;
$('#Print').click(function () {
$('#embed').remove();
URL= 'url';
setTimeout(cPrint, 100);
});
function cPrint() {
window.print();
$('#div').append('<embed id="embed" src="' + URL + '" />');
}
});

Related

Why chrome shows alert randomly when try to open custom protocol url with location.href?

i had took a look to another threads about chrome and custom protocol apps, but i couldn't resolve a doubt i've got. In my web app, when you click a button it fire a new tab with an webpage (window.open(url, "_blank")). The new tab is opened with the url (annother web app with https protocol). This url fire a javascript function on load that verifies some things and then generate a custom url, for example myurl://base64code, and put it in an existing iframe in this way windows.frames['myframe'].location.href=theCustomProtocolUrl. i tried in different ways (location.replace, create a new iframe and set the url, etc) and i always have the same problem. If i refresh (ctrl f5) the page it always show the dialog or if i open the link with the developer console opened. But if i click my button and the page is opened in a new tab it doesn't work only if i refresh (ctrl+f5). This works perfectly on IE11, it launch the app directly.
Any ideas why chrome, and edge, works like this?
UPDATE: I have found the reason, is i use the protocolcheck.js (https://gist.github.com/vladimirtsyupko/cfcd332476b16683bb0b) library.
First i tried to open a protocol with the timeoutHack (it use blur event) and then, after failing, it fires the other url (in this case https) and the dialog doensn't appear. I found a bug with blur event on chrome > 85 https://bugs.chromium.org/p/chromium/issues/detail?id=1137801
Thanks in advance

window.addEventListener('unload', function () { } not working on Mac Safari. It works fine on Chrome

I'm trying to add bounce reporting for my landing page and have added the following code in Javascript (prefer to use pure Javascript).
window.addEventListener('unload', function () {
this.alert("unloading page");
reportBounce();
});
In reportBounce() I make an AJAX call to let the server know. I don't care about the response and am not showing a popup or anything.
The reportBounce fires up when on Chrome browser on Mac, but it does not fire when on safari on Mac. I am yet to try other browsers and OS combinations.
I've seen several questions, some talk about Back/Forward cache, some about Safari on IOS and using 'pagehide' instead of 'unload' but none that actually worked for Safari on Mac.
I was hoping there be a standard function that does the check for browser
and adds the correct event for this need.
Please advice on how to get this to work. Thanks!

How to Automatically redirect website IE browser to Chrome browser?

Recently we migrated to latest version of application which allows the user to open application in any browser.
Earlier it use to support Only IE browsers.
After migration many users still open the application in old browser.
Since the application is very slow in IE browser.We are looking for a solution that will automatically open the URL/Login Page in Chrome browser when user opens in IE browser.
i.e., when a user open URL in IE browser it automatically open the same URL in Google chrome browser.
Google Chrome Legacy Browser support allows this. Under the "Hosts to open in Alternative Browser" policy, put in an entry for the site you want to force to open in Chrome, preceding it with an "!". Example:
!https://www.somesitetoopeninChromeonly.com.
If i understand it correctly, the users open a page in IE and when they click an url on that page, it will open that URL in Chrome.
I guess, you can't do this. You can use target="_blank" to open a new tab in the same browser.
If you want to open a link from an application in chrome and not in IE, you can change the default browser to chrome. Click on Start, type the "default app settings" and change the default browser to chrome.
I think the best solution is to let the user open Google Chrome manually by informing about it.
It is possible however, to make a document called "chrome.hta" for example, with the contents shown below, and then link to it on another page. (This will only work in Internet Explorer, not Edge)
<script type="text/javascript" language="javascript">
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
var website = "http://example.com/";
oShell.ShellExecute(commandtoRun, website, "", "open", "1");
window.close();
</script>
The user now has to press "open" and "allow" after they click the link referring to the .hta file.
Now, on the page where you link to the .hta document, you can make the page detect the browser and adjust the link accordingly:
<a id="link" href="example.com">My Application</a>
<script>
if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1))
document.getElementById("link").href = "example.com/chrome.hta";
</script>
A bit late, but we have two different solutions for this:
We use a javascript: link to use ShellExecute to run a small exe helper application that checks if Chrome is installed, and if it is, open Chrome to the URL parameter, optionally with switches (e.g. --use-system-default-printer and on shared logon PCs, --incognito). This requires configuring special permissions for the site in Internet Options|Security.
Now we can also use the microsoft-edge: protocol to open sites in Edge.
You could also install your own protocol for opening sites in Chrome but you would need a helper application to re-write the URL. I have one written to add microsoft-edge-private: to open links in Edge in InPrivate mode.
To open the webpage in Microsoft Edge you can try the below code.
TEST

Debugging Chrome extension default_popup using dev tools

I'm trying to do some simple debugging on a Chrome extension. When I try to catch an event ID and show it in an alert, Chrome immediately closes the alert and the default popup window making it impossible to tell what was in the alert. For instance:
$("a[data-toggle='pill']").on('shown.bs.tab', function (e) {
alert(e.target.id);
});
To instead log this to the console, I could do:
$("a[data-toggle='pill']").on('shown.bs.tab', function (e) {
console.log(e.target.id);
});
However, if I inadvertently close the popup or have to reload the extension, then the console window I opened using "inspect popup" on the popup will also be closed. This makes for a very tedious debug process.
What is a better approach to debugging and test Chrome extensions for the default_popup?
You can debug your chrome extensions like this
go to this link
chrome://inspect/#extensions
you can see your installed extensions and you can inspect them
:)
grab the link to the extension and change url to popup window url
in my ex: I changed background.html --> popup.html

apprequests dialog does not function in chrome

I am using the following javascript line to open a facebook app requests dialog:
FB.ui({ method: 'apprequests',
message: 'A request especially for one person.',
data: 'tracking information for the user'
});
When I click on the button that is to open this dialog in Firefox, it works just fine. However, in Chrome, the new window pops open, and immediately closes before any user action is taken.
Anyone know how to fix this?
Thanks
I had the same issues with chrome.
I fixed the problem by deactivating some add ons in the chrome settings, which may have been maleware, adblocker etc... now everything works as expected.