Via a Chrome extension, is it possible to change text in the Omnibox (address bar), for example after the chrome.omnibox.onInputEntered event is fired? I'm writing an extension that does certain conversions of values and one method of input is via the omnibox's extension keyword mode. I would love to be able to display the converted value right inside the omnibox itself after they hit Enter, instead of having to display some type of dialog/pop-up window, since their focus is already on the omnibox.
You cannot alter the contents in the omnibox via Extensions, but, you can use the HTML5 History API to do that (not URL text).
I don't know if it will work for your case, but doesn't hurt to try out.
https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history
You can use the pushState to change the URL something like this:
history.pushState(null, "New Title", "newpage.html");
There is a good possibility it wont work because it is dependent on the url for the DOM.
Related
I wanted to create very small extension for website that will automatically copy some value to the clipboard.
The problem is that I want it to copy the value even if browser is not focused e.g.:
I open the website, my extension listens to the change on the page
I open different application
If something changes on the page then the extension should copy some value
Main application that I'm working with is still focused but I can CTRL+V paste value copied from the website without alt+tab
I tried to use Clipboard API:
navigator.clipboard.writeText(...)
but I don't think it will work because browser have to be focused(I think).
When page is focused then copying works fine. If I try to switch to different application I get an exception when my extension tries to copy the value:
DOMException: Document is not focused.
Is there any way to do this?
This is not possible for security reasons.. It's hard to imagine anyone wanting this behavior...
This document has a lot of good info..
In Chrome, you can request clipboard-write permissions to write to clipboard outside of a small user generated event, although it does not appear as though Chrome limits you to when you can write to clipboard.. According to the article below, you can write to the clipboard in Chrome from the background, etc.. See the note at the bottom of this section for more info.
If Chrome does allow you to write to clipboard from the background or if the window is not selected, you could possibly use the Page Visiblity API to kick off the copy event when "that" specific window is not visible.
You could possibly even use the window.addEventListener('blur', function(){...}) handler to test, etc...
All in all, this MAY be possible in Chrome, but it is definitely not supported in Firefox.
You can check out the differences between browsers and how they handle clipboard related events/permissions/etc, here..
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).
Subject:
I'm in the process of creating a chrome extension and, for certain features, I would like to copy some text to the clipboard and automatically paste it into whatever element has the focus for the user.
Getting my text into the clipboard is no problem. I can simply create a textarea in my background page, set its value accordingly and then select it's contents. Then, I can use document.execCommand("copy");
Problem:
The problem comes when I try to use document.execCommand('paste') in my content script. It works fine on simple text areas (like the one I'm typing in now). However, on many sites, it tends not to work. This typically happens when the editable element is inside an Iframe, or is actually a custom <div> rather than a vanilla <textarea>/<input>
Even though my trivial attempt fails to work in these cases, the built-in paste option that is provided by Google, works every time without fail.
Is it possible for a chrome extension to mimic this functionality in a customized context menu option? If so, how can this functionality be achieved?
Additional Info:
This operation is invoked when a context menu option is clicked. Said context menu option is only visible when the element currently in focus is categorized as editable by the chrome.contextMenus API
Similar Questions:
None of these provided me with a satisfactory answer
the proper use of execcommand("paste") in a chrome extension
clipBoard using chrome api execCommand
So far, all the answers are concentrated in capturing the events inside the webpage. But, is it possible to retrieve the last 'text' data in the clipboard using javascript?
What I want to do is that when the user click a textarea, it automatically changes its value to the last copied element from the system clipboard (from any page or other application).
Sadly, there is no simple way to do this. You can use flash hacks (I don't know them personally) to get access to the clipboard whenever you want, but otherwise, you're limited to accessing the user's clipboard (in your case, to read what is on it) during system clipboard events (triggered by keyboard shortcuts or from the browser's menus).
In IE, you can access the clipboard whenever you want using the following code:
window.clipboardData.getData('Text');
But if it isn't during a system clipboard event, the user will be prompted as to whether or not they want to grant you access.
You can get a workaround in Chrome by using a chrome extension that grants your site/app clipboard permissions. From there you can just force a paste event using the following code.
window.execCommand('paste');
This should cause whatever is on the clipboard to be pasted (since your text area is selected, it should paste into your text area).
That's probably as far as you'll be able to get, though, unless you figure out a way to get flash to do it for you (ZeroClipboard seems like a promising option).
If you're interested in some more details, I wrote a technical blog post on this subject after doing extensive work on this at Lucidchart (where I work).
I'm working a lot with NVDA to test website accessibility.
One way to move through a website is to use the tab key. So to reach an area that I want to test, I often have to press the tab key until I reach the needed area. This sometimes is very cumbersome and means repeating the tab key again and again after page refreshes.
It would be very nice to somehow set the focus manually, e.g. by right clicking on a link and choose "Set focus" or something like that. It would be even greater to have an extension which automatically sets focus to a specified element after each page refresh, so when developing, the focus is always on the right element after a page refresh.
Is there any browser extension (Chrome/Firefox) for this? I found some extensions that allow to inject custom JS/CSS (Control Freak, JScript tricks, Script Runner for Chrome) which can be used for something like this, but it's still a bit of a hassle.
You can do this using browser cache to save the last field accesed and then you can focus the concrecte input with something like
$(selector).focus(); //for example with jQuery.
Store/Retrive data from browser cache:
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
http://www.w3schools.com/html/html5_webstorage.asp