Using chrome, a call to
navigator.mediaDevices.getDisplayMedia()
will forcibly focus whatever it is you chose, either a tab or window.
This is not very user friendly given my particular use-case of wanting to stream multiple tabs, as you would have to renavigate to the particular tab that calls this api every time you start a new stream.
Is there any way to get around this barring automatic tab refocusing after media selection?
A chrome api solution is welcome since I am making a chrome extension.
Related
I am currently working on a screen capturing feature in chrome using
navigator.mediaDevices.getDisplayMedia
I am only able to open a user selection where the user can choose from all the given displaymedias. Is there any way to go around the selection and select a tab via the tab name automaticly?
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
I have read the privacy and security part in which it says that
In addition, user permission is always required to access the user's audio and video inputs.
but im still wondering if there is a way?
very few available constrains for getDisplayMedia
getDisplayMedia({preferCurrentTab:true}) // in chrome 96
hopefully getViewportMedia, getViewportScreenshot coming soon
Chrome implement new feature which is called auto tab discarding through this feature enable user when user not on the tab that tab will discard and when user re click on that tab chrome auto refresh that tab. here is the link of Article. this is is very good feature But my problem is I'm showing notification when our tab is active in chrome but because of this feature our Tab is discard and not able to show notifications anymore.
My Question is :- How to Disable this feature or there is any way to keep my tab active or any way to prevent that from discarding?
Users can switch off automatic tab discarding by setting the respective flag in Chrome using this link: chrome://flags/#automatic-tab-discarding
But every page with states depending on user input do have the same problem like yours. Usually, you can prevent unloading a page with handling the onbeforeunload event in JavaScript. Unfortunately, Google does not prevent a solution for this on all systems, despite many users had problems with this feature already in the experimental phase, as you can read in the user comments:
https://developers.google.com/web/updates/2015/09/tab-discarding
For ChomeOS, the problem seams to be fixed:
https://bugs.chromium.org/p/chromium/issues/detail?id=123049
On Android, automatic tab discarding is quite aggressive and prevents using Chrome for applications with significant user input, imho.
On Windows, automatic tab discarding only starts if the available memory is low.
Sorry for not coming up with a proper solution here (I'd be really happy to have one) - I did extensive research and this is all I could find.
I would like to get the URL of the current tab within a page action popup.
At first it seems obvious: Just use the tabs API. But that doesn't seem to be available on Android if I deciphering the docs correctly. So I kept looking for something else and found the onClicked event of the pageAction API.
The pageAction API seems to be listed as compatible with Android and the onClicked event is marked as supported. So that implies that it would actually return a tabs.Tab object. But does it really? Has anyone tried it?
What is the best way to retrieve the URL? I know I could just use a content script and let that run in every single tab and create a long lived messaging connection to send the URL to the page action popup whenever it is requested. But that would be very inefficient and make the code insanely complicated compared to how easy it would be using the tabs API.
Is there anything else I could do?
Current (Firefox 54 and later)
As of Firefox 54, the tabs API is available in Firefox for Android. This means you can use the normal methods available to desktop Firefox. Specifically, chrome.tabs.query() or browser.tabs.query(). However, you will need the activeTab and/or tabs permissions in your manifest.json.
chrome.tabs.query:
chrome.tabs.query({active:true,currentWindow:true},function(tabs){
//'tabs' will be an array with only one element: an Object describing the active tab
// in the current window.
var currentTabUrl = tabs[0].url;
});
browser.tabs.query:
browser.tabs.query({active:true,currentWindow:true}).then(function(tabs){
//'tabs' will be an array with only one element: an Object describing the active tab
// in the current window.
var currentTabUrl = tabs[0].url;
});
Prior to Firefox 54
If you have defined a page/browser action popup
If you have defined a popup for your page/browser action, then the onClicked event does not fire. Your popup is not passed any information when it is created/shown. Thus, you will not receive a tabs.Tab object. The normal way to obtain tab information is from tabs.query, which, as you have already determined, is not (yet) available in Firefox for Android.
The APIs available to Firefox on Android are quite limited. For what you are wanting to do, using webNavigation events to keep a record of each tab's frame 0 URL would be more efficient than a content script in every page. You could use the webNavigation.onCommitted or webNavigation.onCompleted events depending on your needs. You will need to assume that the active tab of the current window is the one which most recently had a webNavigation event, or perhaps you could also monitor webRequest events. However, any way that you do it, which tab you assume to be the current tab will just be an assumption, and will be inaccurate under some circumstances.
A more accurate URL (and active tab determination) requires using a content script
If the page that is being visited changes the tab's URL through some method that does not trigger navigation, using webNavigation events will not give you the updated URL. As you have identified, without the tabs API, the only way to be certain you have the actual current URL for the tab, when you define an actual page/browser action popup (and thus don't get a tabs.Tab object), is to inject a content script into every page. You will either need the content scripts to continuously update the URLs, or be listening with storage.onChanged for a request for that information from your background/popup script. Communication from the background/popup scripts to content scripts must be accomplished through the storage API due to not having the tabs API (i.e. no tabs.sendMessage).
Using page/browser action onClicked
An alternative, which I have not tried on Firefox on Android, would be to not define an actual page/browser action popup. If you don't define an actual popup, you receive the onClicked event (getting the tabs.Tab Object with both the active tab's ID and the URL) and then can open a pseudo-popup1.
1. The implementation of opening a a pseudo-popup in my linked answer uses the tabs and windows APIs which are both currently unavailable for Firefox for Android. It could be re-written to use the above mentioned webNavigation listener to track tab URLs and window.open() to open the window used for the pseudo-popup. Again, I have not tested this with Firefox on Android to determine that it actually works.
You can get it this way with webextensions. Take into account that if you want to debug a popup, you have to "prevent popups to be closed" (4-squares icon at the top-right of the browser's toolbox)
var activeTabPromise = browser.tabs.query({active: true, currentWindow: true});
activeTabPromise.then((tabs) => {
console.log(tabs[0].url);
});
I hope this will help you,
The gist: What's the best way to escape a Flash object's focus on a webpage?
Context:
I have a hotkey listener (an AutoHotKey script) running in my tray. If the script detects the command Alt+Shift+F6 while I am clicked into a Flash object on a webpage, it activates and sends key combinations to Flash to pull certain data logs. After this process completes, I want to call up a JavaScript file on that same browser tab that requests additional information from the user - basically, a tiny UI with additional text fields available in a third-party bug tracker. To do this, I want to send a javascript: command to the address bar using Ctrl+L and having AutoHotKey paste in the full call to the JS file.
A visualization of a possible environment:
The problem:
I need the user to be clicked INTO Flash in order to pull the data logs. However, I need the user to be clicked OUT of Flash for Ctrl+L to actually work - Flash appears to eat all keystrokes at the browser-level when one of its objects has focus.
A possible solution: The easiest way to go about this would be to simulate clicking on the stage, which borders my Flash object on every side. This should work, but I must assume the stupidest possible user. Such a user would somehow limit their current browser window to only be as big as the Flash object (if not smaller), click into it, and attempt to use the hotkey. In this case...I have no idea where I should click, because it could be outside the browser. Further, I don't believe I can assume that all browser address bars are similar amounts of pixels south from the top of the window.
Additional complicating factors:
I want this to work for the user's default browser. (IE, Chrome, Firefox, Safari are my big targets.)
AHK does not provide any native DOM or COM hooks to anything except IE.
Ctrl+Tab and Alt+Tab shenanigans do not appear to work. That can get me to other tabs/windows, but returning to the tab/window with the Flash object still causes Flash to 'eat' further keyboard input.
While I'd be open to using another scripting language than AHK if it could overcome this Flash focus hurdle, I do not know how to create a keylistener that sits in the users tray until activated by a hotkey.
I have no access to the Flash object's code, and it contains no logic to interpret a key combination as a way to break focus or launch a script.
Would it be possible to use WinMaximize to maximize the size of the window? If you do that it should be easier to set up the script to avoid clicking outside the browser.
Perhaps look at ControlFocus and/or ControlSend (using the "edit1" control in IE and FF -- unfortunately, Chrome doesn't expose the "address bar" as a "control" this way but if you test for Chrome first, you can implement your "click outside the Flash box" method for that case).
I have an application which had developed according to IE6.
Now Because of IE8 tabbing features not the application have been start giving problem.
The Problem is that,
if I have opened first context in "tab1" and then open second context in "tab2".
Now when I back to "tab1" and refresh the page then it loads the second context that is new one.
This is logically correct but I want to block the user while opening the second tab so that user restrict to only first tab.
So I have been come to conclusion that we can do this with JavaScript by getting some tab event, but I am not too much familiar with JavaScript.
Please tell me is there any solution if you have in your mind for above problem,
or tell me is there any way so that we can catch the tab event.
Praise all things glorious: There is no way to prevent a user from opening a new tab. In Firefox, you can cruelly prevent a user from using keyboard shortcuts to open a new tab by returning false from an input element's onkeypress event, but it's still possible to open a new tab otherwise.
The solution? Well, from what you're saying, it sounds as though you're using the session to store the user's current page (and, well, most everything else, but that's another story). Having spent a lot of time using a web application that was built that way, I can tell you firsthand: don't do this! The web already has a wonderful method for storing the user's current page: the URL.