How to get resize events in Chrome desktopCapture - javascript

I'm using Chrome's desktopCapture in an extension and I have an issue that I'm attempting to work around. Any help would be greatly appreciated. I cannot post any source, but the chrome extension itself is commonly available and used on the web.
Issue
The issue is with resize / dimension changes that may occur while desktopCapture is capturing / streaming to the server. These changes can often occur seemingly too fast for my client to handle, causing the client application to crash.
Solution
I'd like to get some event or notification when the capturing end detects a resize of the area being captured; for instance a window which has been clicked and is being dragged to resize it.
An alternative would be if the event.data can be queried for width / height.
Research
I've google'd and searched the chrome / webrtc issues; I've come up empty thus far. There really isn't any good implementation information available from what I've found.
Going through the Chromium codebase is not an option for me; I am not a C/C++ developer.
What I would like from You
If you have experience with the desktopCapture offering, please share what you know. If you don't have any idea what I'm asking or have nothing constructive to add, please ignore this and move on.
Commentary
As of July 17th 2015, it would appear that there is a bug or missing support for resize events in Chromes desktopCapture extension. I will file an enhancement request with them and see where that goes. It probably won't help that "normal" WebRTC streams aren't "expected" to change dimensions during streaming and thus it is not handled.

Attach the captured stream to a video element and listen for the onresize (onsize?) event. Should also work for hidden elements if you don't want to display something at the capturing end.

Related

Would the version of Chrome affect the behavior of a JavaScript library?

I ran into a bug that seems very nuanced and strange. I am using OpenLayers (v4.0.1) in a web application to display multiple WMS layers from a GeoServer (v2.8.2). Everything seemed to be working great until Windows 10 did a big update. Shortly thereafter, my browser began to crash when attempting to view the page on which the map and all of its layers should be displayed.
After a lot of digging, it appeared that this issue only shows up in Chrome Version 60 (60.0.3112.90 to be exact). I tried to reproduce the issue on multiple OS's and browser combinations (Linux/Windows/Mac and Firefox/IE/Edge/Chrome Version 59) and it works great everywhere except on Chrome 60 (across all OS's).
Though still hard to pin-point exactly, when doing a step-through of the JavaScript to find where the hang-up occurs, it is definitely happening somewhere inside of the OpenLayers code. Another key discovery is that the error does not occur at all if the browser window size is "small" enough. In other words, if I resize my window and try again, it will suddenly work consistently once a somewhat-random-seeming, certain browser size is reached. It seems to be more area-dependent, though, than a specific height/width constraint, as various height/width combinations will either work or not work.
At this point I have no great idea on how to resolve this issue, so I'm starting here by simply wondering if anyone knows if it would make sense that something in Chrome 60 is changing the behavior of the OpenLayers JavaScript library? If so, I'd want to open up an official GitHub issue with them. If not, would it be a Chrome issue I'd report? I'm reluctant to believe it is something that I have programmed, as it works in every other browser.
Thoughts?
This does indeed sound like a Chrome bug. Please file a bug at crbug.com/new, and include:
repro instructions (ideally, a link to a site that will trigger the crash)
any crash reports you see in chrome://crashes (if this is what caused them)
If you post the bug number here, I'll make sure it gets looked at. Thanks!

How to actually implement drag'n'drop in Javascript / Metro-UI under Windows 8

Somehow I must've missed the proper documentation for something as simple as this. Searching via Google does not exactly yield useful results either.
So, here's what I want to do: Draw a rectangle (div), make it draggable and drop it somewhere else, with a proper validation that the drop point is an actually valid one.
How would I go about doing that with the tools provided by the Visual Studio 11 Beta?
All I've found so far is the onDragging-Event which is not really helpful due to the scarcity of information provided.
Code sample would be great, I could also live with a link to some blog or such.
Edit: Drag and drop through touchscreen input, that is, not through the "normal" mouse interaction.
Just got a reply from a Microsoft employee: It's a bug:
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/88cfb689-2e38-417c-a2be-9682f1a23ae4/
So, until that bug is fixed, it seems you really have to roll your own.
The following link a walkthrough of HTML5 drag/drop in IE10 from the IE blog. IE10 is the engine for Windows Web Apps so this will work in your Windows 8 app.
http://blogs.msdn.com/b/ie/archive/2011/07/27/html5-drag-and-drop-in-ie10-ppb2.aspx
Up until and including the beta (CP) we were able to use the dragstart, drag, dragend events even for touch input in Metro. In the newer builds this has stopped working (events don't fire anymore) and it looks like we'll have to switch to MSPointerMove et al. for handling touch-dragging.
From a few samples I created it seems that standalone IE has never supported dragstart, drag and dragend for touch - in other words touch drag works in my sample inside beta Metro, but same file doesn't work inside normal IE there.
Re the answer from Microsoft employee mentioned below, I believe that bug is unrelated to the issue of touch-dragging.

Chrome and SVG (Raphael), trouble with drawing "off-screen"

I'm working on a prototype system which will act as a proof of concept that an existing system can be made a lot more interactive.
It basically emulates our main software package but over the internet using JSONP requests to update a load of images and Raphael vectors to make it look like everything's running.
I'm having trouble on Chrome however with Raphael not drawing vectors "off-screen". What I mean by "off-screen" is that the main app runs through an iframe as it relies on cross-domain long poll comet through AJAX to get communicate back and forth. Below is an image demonstrating what I mean.
Here I've scrolled a long a little bit in the iframe to look at the bits "offscreen" and you can hopefully see that the grey arrows aren't rendered. I've used Chrome's developer tools to highlight over the SVN tag, showing that it's only given 450px by 810px to the SVG tag, which is the same size allocated for the iframe.
It's worth pointing out that it renders fine in Firefox. Any ideas?
I've had a similar problem and found a bug report for the WebKit project that seemed related:
https://bugs.webkit.org/show_bug.cgi?id=64823
According to the comments, it's a bug in the rendering engine and there's no workaround aside from losing the iframe or resorting to other means of scrolling the SVG viewport (like moving all the elements within the SVG element).
On the upside, version 16.0.912.21 has been released to the beta channel today and it seems that the bug has been fixed. I've also checked the latest chromium build (17.something) and the bug hasn't resurfaced. I'm guessing the fix should find its way into the stable channel in a couple of weeks.

How to optimize website for touch devices

On a touch device like iPhone/iPad/Android it can be difficult to hit a small button with your finger. There is no cross-browser way to detect touch devices with CSS media queries that I know of. So I check if the browser has support for Javascript touch events. Until now, other browsers haven't supported them, but the latest Google Chrome on dev channel enabled touch events (even for non touch devices). And I suspect other browser makers will follow, since laptops with touch screens are coming. Update: It was a bug in Chrome, so now the JavaScript detection works again.
This is the test I use:
function isTouchDevice() {
return "ontouchstart" in window;
}
The problem is that this only tests if the browser has support for touch events, not the device.
Does anyone know of The Correct[tm] way of giving touch devices better user experience? Other than sniffing user agent.
Mozilla has a media query for touch devices. But I haven't seen anything like it in any other browser:
https://developer.mozilla.org/En/CSS/Media_queries#-moz-touch-enabled
Update: I want to avoid using a separate page/site for mobile/touch devices. The solution has to detect touch devices with object detection or similar from JavaScript, or include a custom touch-CSS without user agent sniffing! The main reason I asked, was to make sure it's not possible today, before I contact the css3 working group. So please don't answer if you can't follow the requirements in the question ;)
It sounds to me like you want to have a touch-screen-friendly option, to cover the following scenarios:
iPhone-like devices: small screen, touch only
Small screens, no touch (you didn't mention this one)
Large screens, no touch (i.e. conventional computers)
Touch-screen-enabled large screens such as iPad, notebooks/pcs with touch screens.
For case 1 and 2 you will probably need a separate site or a CSS file that eliminates lots of unnecessary content and makes things larger and easier to read/navigate. If you care about case #2 then as long as the links/buttons on the page are keyboard-navigable then case 1 and 2 are equivalent.
For case 3 you have your normal website. For case 4 it sounds like you want clickable things to be bigger or easier to touch. If it's not possible to simply make everything bigger for all users, an alternate style-sheet can provide you with the touch-friendly layout changes.
The easiest thing to do is provide a link to the touch-screen-version of the site somewhere on the page. For well-known touch devices such as iPad you can sniff the user agent and set the touch stylesheet as the default. However I'd consider making this the default for everyone; if your design looks good on the iPad it should look acceptably good on any notebook. Your mouse users with less-than-stellar clicking skills will be pleased to find bigger click targets, especially if you add appropriate :hover or mouseover effects to let users know that things are clickable.
I know you said you don't want to sniff user-agents. But I'd contend that at this time the state of browser support for this is in too much flux to worry about the "Correct" way to do it. Browsers will eventually provide the information that you need, but you will probably find that it will be years before this information is ubiquitous.
Good news! The editor draft of CSS4 Media Queries have included a new media feature 'pointer'.
Typical examples of a ‘fine’ pointing system are a mouse, a track-pad or a stylus-based touch screen. Finger-based touch screens would qualify as ‘coarse’.
/* Make radio buttons and check boxes larger if we
have an inaccurate pointing device */
#media (pointer:coarse) {
input[type="checkbox"], input[type="radio"] {
min-width:30px;
min-height:40px;
background:transparent;
}
}
It's also possible to test the media query from JavaScript:
var isCoarsePointer = (window.matchMedia &&
matchMedia("(pointer: coarse)").matches);
Updated Feb. 11th. 2013 On Windows 8 recent versions of Chrome (version 24+) detect touch-hardware when launching the application and expose touch events. Unfortunately if "pointer:coarse" returns false, there is no way to know if it's because pointer media queries are not implemented or because there is a fine pointer. WebKit haven't implemented "pointer:fine" yet, so we can't check that either.
Update Sept. 26th. 2012
Tested in Safari on iOS6 and Chrome on Android 4.1.1 and it's not there yet. 'pointer' and 'hover' media-queries landed in WebKit May 30th. According to the User-Agent, Safari uses WebKit branch 536.26 from April 25th, and Chrome on Android uses and even older one (535.19). Not sure WebKit branches from User-Agent strings are to be trusted, but my test page is not able to detect pointer media queries either.
The implementation from May only implements the pointer media query for touch devices, so pointer: fine won't work for devices with a mouse.
I don't know if a standardized media query like Mozilla's will solve the problem by itself. Like one of the Chromium developers said in that discussion you linked, the presence of touch event support in the browser doesn't mean touch events can or will fire, or even if they do, that the user will only want to interact via touch input. Likewise, the presence of touch input support in the device doesn't mean the user will use that method of input - perhaps the device supports mouse, keyboard, and touch input and the user prefers the mouse or some combination of the three input types.
I agree with the Chromium developer that supporting touch events was not a bug in the browser. A good browser should support touch events because it might be installed on a device that supports touch input. It's the website developer's fault that he took the event support to mean the user would be interacting via touch.
It seems we need to know two things:
(1) What are all the supported input types on the device
(2) What are all the supported event types in the browser
Since we don't know #1 right now, there is one approach proposed by PPK of quirksmode that I like. He talks about it here: http://www.quirksmode.org/blog/archives/2010/02/do_we_need_touc.html#link4
Basically, listen for touch events and mouse events, and when they happen, set up the UI accordingly. Obviously that's limiting to the developer. I don't think it's a valid approach to your problem with link size because you don't want to wait for interaction to alter the UI. The whole point is to present a different UI (a larger/smaller link) before any interaction occurs.
I hope you make your proposal and it gets included in CSS3. Until then, as much as it pains me to say it, user agent sniffing looks like the best approach.
p.s. I hope hope hope someone comes here and proves me wrong
Google Chrome has a command line switch for enabling touch events. Disabled by default. So until they enable them for everyone again (hopefully they won't), it's possible to detect touch with the help of javascript like I described in the question..
Update jun 3 2010: This actually got into the stable version on 25th of May 2010 :( Don't know it it was a mistake or not.
Have discussed the issue on the w3c mailing list, but I doubt anything will happen very soon. http://lists.w3.org/Archives/Public/www-style/2010May/0411.html
They might discuss this during TPAC in November.
Update sep 30 2010: Supposedly fixed in Chrome 6. Haven't had time to downgrade to stable yet to verify. Since Chrome upgrade automatically this problem should already be gone :)
Read this if you're considering using media queries:
http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
and http://www.quirksmode.org/blog/archives/2010/09/more_about_medi.html
Update may 16th 2011: W3C is now working on a Touch Events specification, but more or less refused to hide touch events for terminals without touch hardware. So don't expect the touch event detection to work for long.
Update june 6th 2012: The W3C CSS4 Media Queries (Editors Draft) spec have something very interesting. See my separate answer about this.
No, there is no such thing.
CSS has the screen size option, which will allow you to optimize layout, but that's all.
There is also media="handheld" but that also doesn't apply to your requirements.
Feature detection might work using javascript, however, there are issues with different events for different devices. PPK (the man behind quirksmode.org) is doing a huge amount of work checking what javascript is possible for each mobile/handheld device, and it's proving that nothing seems to be standard with these devices and yet this STILL doesn't apply to your requirement for touch laptop devices.
(honestly I dont know why you are concerned about a device that isn't even out yet, be pragmatic and worry about it once it's here and you can test it)
PPK's work on mobile browser and touch events, will save you hours. Check it out here
Apple has TouchEvents defined only for iPhone OS FWIW
Not a complete solution, but you might want to simply outright avoid any small buttons. While small buttons are more of a usability problem on touch devices, they are always hard to use, even with a big screen & mouse.
If you just pay attention to using suitably big buttons with enough space between them, everyone will benefit. Plus, it will force you not to clutter your interface with too many small buttons :-).
try using tables and make a full cell to be a link...
i'm working on that in my website...
it's not working well so far...
but you might find a way...
on this way, no need to overload your website with javascript and functionality detection...
you can give it a relative size instread of a fixed size...
and in this way, your website can be viewed in a desktop as is viewed in a iphone...
think about this idea...
any sugestion is apreciated...
See http://crbug.com/136119 for support for adding pointer:fine in Chrome. It is actually possible to detect whether pointer:coarse is supported (to distinguish unset from not supported) - just create the media query yourself and test in javascript whether it parsed properly.
Eg., today "#media (pointer:coarse)" in Chrome shows up:
> document.styleSheets[0].rules[5].media[0]
"(pointer: coarse)"
But unsupported bogus values like "#media (pointer:other)" don't:
> document.styleSheets[0].rules[8].media[0]
"not all"
You won't have any control over detecting touches, and even if you did the logic steps to figure out what exactly the user is trying to touch is complex and best handled by the device itself.
Your best bet is to create a mobile version of the site or an alternate stylesheet that is loaded when you detect a mobile device with Javascript.
If you are using PHP, this is a good solution:
http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/
You can detect whether the browser is a phone from the serverside by sniffing the browser request details, and if so, display alternative/extra stylesheets/js/html

How to trigger Mouse-Over on iPhone?

This might seem like a really dumb question, but I am writing an application and I have come across where my mouse-over, mouse-click and mouse-hover need different events bound to them. Now on Internet Explorer, Firefox, and Safari. It all works as expected.
However, on my iPhone the actions will not trigger. Now my question is are their any specific ways I can have the Mouse-Over essentially be fired when I hold my finger down and trigger an event?
An example where this doesn't work is right on this website when you hover over a comment it is supposed to display the +1 or flag icon.
I am using jQuery.
The answer is in the documentation that Remus posted. If you add an onclick = "void(0)" declaration, you will instruct Mobile Safari that the element is clickable, and you will gain access to the mouseover event on that element.
More info here
I think you need to reconsider your design for the iPhone (and any mobile for that matter). iPhone web interfaces shouldn't depend on mouse-overs and hovers, as they just complicate the interface significantly.
I strongly recommend that you design a new interface that is optimized for mobile viewing, that don't require clicking on small tiny arrows just to show more options.
Mobile Safari has no mouse and hover events (at least not in the usual accepted sense), they are explicitly called out in Creating Compatible Web Content Unsupported iPhone OS Technologies:
Mouse-over events The user cannot “mouse-over” a
nonclickable element on iPhone OS. The
element must be clickable for a
mouseover event to occur as described
in “One-Finger Events.”
Hover styles Since a mouseover event is sent only
before a mousedown event, hover styles
are displayed only if the user touches
and holds a clickable element with a
hover style. Read “Handling Events”
for all the events generated by
gestures on iPhone OS.
Yeah...I don't think anyone posing the question actually expected the device to "sense" a hover or mouseover. Actually you'd have to be pretty arrogant to assume someone actually meant that. Some method of triggering those event handlers is what is desired. I can definitely see a use for them in "hint" text appearing above items.
And whomever said not using mouse events makes a cleaner, simpler experience is taking their own opinion a bit too seriously. Those can greatly enhance a web page/application experience or make them worse. It's a matter of prudent usage.
The only answer anyone provided here worthwhile is whomever said it is best to have an alternate site optimized for mobile. Or possibly use a content management system that generates the page based on the browser type (similar to how Wikipedia works).
Congratulations on discovering the first thing about touch screen UI design. The bad news, is that what you want just is not going to happen.
The good news is that this will force you to make a much easier interface, for both iphone users and regular web users.
You simply cannot have a mouseover or hover functionality on touch screen devices, unless you can move a virtual pointer (though no touch UI offer that kind of functionality), but that would defeat the point of a touch screen UI.
Touch screen UI's are a paradigm shift and retro-fitting mouse-pointer UI interfaces back into touch UI design only limits and damages your solution.
Writing a mousehandler in javascript seems fairly straightforward, although I can imagine it being easy to get a lot of edge cases wrong.
The good news is, someone wrote a javascript mouse-handler/emulator whatever -- as a bookmarklet. It's called iCursor (not to be confused with the pointless mac app of the same name).
The bad news is, the guy's site (icursor.mobi) has gone off the air, and I can't find a copy, so I can't tell you how well it works. Here's a review (because I can only post one link):
What apple should have done for the iPhone/iPad was make one-finger panning move a virtual mouse pointer, and two-finger panning move within the viewport (as one-finger does now).
Two finger panning is easy; the only reason I can imagine for Apple not doing this is that they actually wanted to break 50% of the websites in the world. Seriously. It's right up there with the evil manipulative attempts to break standards that Microsoft has been doing all these years.
You're a web developer. What do you hate most? Internet Explorer. Because of all the extra headaches it causes you. Well, Stevie had to have his "me too" moment, and you're going to pay for it.

Categories

Resources