How to use chrome.printerProvider - google-chrome

I need to control the printer by specific pdf file in some reason, thus I wanna using a chrome extension to solve it.
However, I found chrome print.provider, these APIs provide some events, but I assumed when the user press ctrl+P will trigger below event, but in fact, it does nothing happens.
chrome.printerProvider.onGetPrintersRequested.addListener(function(printerInfo) {
console.log("onGetPrintersRequested", printerInfo);
});
chrome.printerProvider.onPrintRequested.addListener(function(printJob, resultCallback) {
console.log("onPrintRequested ...", printJob);
});
chrome.printerProvider.onGetCapabilityRequested.addListener(function(printerId,resultCallback) {
console.log("onGetCapabilityRequested ...", printerId);
});
What I misunderstand those events or I type the wrong callback function, is there has any good point to solve it, I found lots of people discuss this question before, but none of the proper answer I excepted.

Related

DataVizExtention: issue with clearing viewables while a sprite is selected

In my code, I have this workflow:
When user wants to see some things, add Sprites using 'DataVizCore.addViewables()'
Use 'viewer.addEventListener(DataVizCore.MOUSE_CLICK, onDotClick)' to show info bubble
When user wants to show other things, call 'DataVizCore.removeAllViewables()' to clear Sprites
Repeat from step 1
This sequence works OK except in one situation.
If a sprite was selected (by clicking on it) before removeAllViewables() is called, I don't get MOUSE_CLICK event for newly added Sprites. In browser console, I see following error is thrown.
CustomViewables.js:318 Uncaught TypeError: Cannot read property 'style' of undefined at ViewableData.getViewableUV (developer.api.autodesk.com/modelderivative/v2/viewers/7.*/extensions/DataVisualization/DataVisualization.js:454)
As a workaround, I added 'event.hasStopped = true' to click event handler to prevent Sprite getting selected internally. That seems to work.
This seems like a bug in DataVizExtension to me. Or, my workflow is wrong?
Thanks
Bandu
Bandu. Thanks for the detailed steps to reproduce this issue. I tried with v7.46.0 version of the DataVisualization.js (latest as of my message) but was not seeing the same issue. I'd be curious if you are using this same version of the Forge Viewer (you can figure that out by looking at the viewer3D.js fetched under the Network tab of Chrome DevTools).
Setting event.hasStopped = true works because it internally avoided the code path calls into getViewableUV that threw the exception, but the flag is meant for other use cases (e.g. overriding default sprite selection behavior).
In any case, I've just tweaked our internal code to make use-cases like yours more robust. The changes will be released with the upcoming v7.47.0. Thank you for your feedback 🙂

How to solve the "non-passive event listener ..." google chrome console message

I made a wordpress plugin used by slick slider, but the slick github project didnt get update related this chrome warning.I dont want change my plugin and search different slider.So, How can I solve this error in shortest way?
I know there are many question about this issue but this question is not dublicate because the answers give same code and I couldnt solve my problem with the code.
What must I do with below code:
addEventListener(document, "touchstart", function(e) {
console.log(e.defaultPrevented); // will be false
e.preventDefault(); // does nothing since the listener is passive
console.log(e.defaultPrevented); // still false
}, Modernizr.passiveeventlisteners ? {passive: true} : false);
A bit late to the game, but still:
As many users reported this problem, I integrated a solution into my own fork of slick slider.
To solve the slick slider issue with passive listeners, you can use this fork of slick. It integrates the fix:
https://github.com/nicolaskopp/slick
You can also grab the patch here and use for your own fork, if you like:
https://github.com/kenwheeler/slick/pull/3422

Usability issue for navigator.geolocation: how to know if the user is being asked for location?

Does HTML's navigator.geolocation have an event handler for 'Currently asking the user if they will share their location'?
I would like to show some text instructing the user to share their location if and only if they are actually being asked to share their location.
Currently I have this code, but it's broken.
It looks smooth the first time, but the second time (when the browser knows this is a trusted site, so doesn't ask the user about sharing their location), 'Share your location' flashes up quickly when the page loads, then disappears behind the map.
// map.js
function gpsSuccess() {
// We have a location - although we don't know whether this is
// because the user has already agreed to share with this domain,
// or whether they have just this second been asked.
$('#sharelocation').hide();
// load map, etc
}
if (navigator.geolocation) {
watchId = navigator.geolocation.watchPosition(gpsSuccess, gpsFail);
}
// map.html
<div id="sharelocation">Share your location</div>
<div id="map" class="hidden"></div>
Any suggestions for a smooth way to give the user some instructions in the body of the page if and only if they are actually being asked to share their location?
I'd consider not showing the "Share Location" message unless the failure callback gets executed.
function gpsFail() {
$('#sharelocation').show();
}
You can include a message in the sharelocation block which explains how to enable location sharing, what you'll do with the information, etc.
Sounds like you might just have a timing issue with the brief delay between getCurrentPosition and your callback. What if you delay the show by a second or so? (I don't know what the jquery-specific method is) Keep a reference to the task so in gpsSuccess you can call clearTimeout with it.

Facebook Login Handler doesn't get fired in Flex4 Facebook API

I have literally spent HOURS trying to solve this mystery... but simply can't seem to get hold of it.
I am using the same code lines (literally!) as the example here (official adobe tutorial) and I get different result.
protected function login():void
{
Facebook.login(loginHandler,{perms:"user_birthday,read_stream,publish_stream"});
}
protected function loginHandler(success:Object,fail:Object):void
{
trace ("login handler called");
if(success){
currentState="state_home";
Facebook.api("/me",getMeHandler);
//userImg.source=Facebook.getImageUrl(success.uid,"small");
Facebook.api("/me/statuses",getStatusHandler);
}
}
Everything works fine, i.e. everything till it is time to fire the loggedin event. I get asked to log in and all permissions are asked correctly. After I log myself in to facebook, the loggedin event doesn't fire. Is there any way of solving this problem??
And I am really desparate... :(
Have you tried debugging the JavaScript of the containing HTML page? I've found that the JavaScript can encounter errors in the communication back to your Flash movie, and it fails silently in the background.
Open the debugger and have a look for any errors - sometimes its down to conflicting embed object Ids in the HTML that throws it.

Can chrome extension background pages have multiple listeners?

I'm building a chrome extension and trying to get data from twitter and then pass that to my contentscript. I'm having a lot of problems with this. I'm able to get the data from the remote site but can't seem to pass it to my content script. I have a listener for when i click the icon using chrome.extension.onclick.addlistener(functionname);. This gets the data. The Problem is once i get the data, i need to send a response to the request from my content script. So i'm also calling chrome.extension.Onrequest.addlistener(functioname);. Before i go on trying to figure out what's wrong with the code, is it allowed to have 2 listeners for 2 separate events in the same page as i've done or can you only have one listener?
I know this is a crazy old question, but I came across this while experiencing a related issue and wanted to share in case it was useful for anyone else.
Make sure you're only calling the sendResponse method at most once if you do have multiple listeners. From the docs:
sendResponse: Function to call (at most once) when you have a response.
The argument should be any JSON-ifiable object. If you have more than
one onMessage listener in the same document, then only one may send a
response. This function becomes invalid when the event listener
returns, unless you return true from the event listener to indicate
you wish to send a response asynchronously (this will keep the message
channel open to the other end until sendResponse is called).
If you do a quick search on Stackoverflow, you will see many examples with code on how to send messages from background page to content script:
https://stackoverflow.com/search?tab=relevance&q=content%20script%20background%20page
For more information how to do this, you can follow the docs themselves, they have great examples:
http://code.google.com/chrome/extensions/messaging.html
From the documentation (copy paste):
content_script.cs
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
else
sendResponse({}); // snub them.
});
background.html
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
});
The fact that you have created a listener for the onClick event and a listener for the onRequest event is not a problem. You can tell by typing out chrome.onClick and chrome.OnRequest at the console for the background page; you'll see they are each instances of type 'chrome.Event'.
If you think about it, if you were only able to create one listener it would greatly reduce your ability to write something useful since you could only respond to one of { onrequest, onclick, ontabchange, onconnect, ondisconnect, etc. }