Google Chrome extension - to open new tab directed to url when a certain url is searched in current tab? - google-chrome

I am very new (started today) to writing chrome extensions but need to write a 'fairly simple' one for tomorrow...
I am really struggling to get my head round it though!
I need to write an extension that opens a new tab or window (whichever is easier!) directed at a predefined url is opened when a certain URL is searched in the current.
An example of this would be if the user typed in www.facebook.com I am trying to get the extension to then open a new tab/window with www.google.com in.
Any help would be much appreciated!
Thanks
Will

In your html of the extension you can specify an anchor tag for the action button which opens a new tab like this
content of the anchor
or if you want to do it programmatically you can
window.open('http://google.com','_newtab');

You cant get at the contents of the omnibox unless you use the omnibox api, which means they have to specify your keyword first before your extension can get at the contents. You could make it open another page once they have gone to a url. You could use a content script that has a matches field that matches the page your interested in and then open a page accordingly.
Content Scripts
http://code.google.com/chrome/extensions/content_scripts.html
Tabs
You can use the tab api to get the current tabs details if your not in a content script. If you are in a content script you can use window.location as stated by Encore PTL. You can also use the tab api to open a tab.
http://code.google.com/chrome/extensions/tabs.html

Related

Chrome: Bookmark / Bookmarklet to open a URL with clipboard-Content

Is there a way to dynamically include clipboard content into a URL of a Bookmark / Bookmarklet in Chrome?
For example, i copy a story number ("test-1234") and want to open it in jira, it would be helpful i could just click the bookmark, something like this:
https://jira.mydomain.com/browse/{clipboardContent}
and it would open the URL:
https://jira.mydomain.com/browse/test-1234
Or is there a chrome-extension that would make it possible?
With chrome.contexMenu API you can select any text ("test-1234") from any web page
and activate a function (present in the contextual menu)
that opens a new tab (or window) with an URL constructed by the fixed part and the parameter in the queue.
You have to grant "contextMenu" and "activeTab" in your manifest.
For further details please read: https://developer.chrome.com/docs/extensions/reference/contextMenus/
I'm doing since years exactly what you've described, but I'm on MacOS and for this I'm using Alfred App (https://www.alfredapp.com). I've created an own Workflow for this. If you're on WIN, then there is something which could be similar to Alfred App --> https://github.com/Wox-launcher/Wox

Force chrome to open url instead of search

When developing and opening custom urls you always have to type **http://**localurl.local/ in order for Chrome to open page and not google search.
Is there some way you can force google to first try to lookup if page actually exists? And if I already have opened url and append something to string I'm being again redirected to google search which is very frustrating.
If you're not following me see this gif:
preview

Chrome Extension - Use Another HTML Source

I'm creating a extension and here is what I want to do.
I have site "www.aaa.com" and the extension I developed can read and navigate DOM element by javascript. However, when I click the extension icon, I'd like get and read the HTML source from "www.bbb.com".
The current page is "www.aaa.com", but want to get the source of "www.bbb.com" in the current page.
How can I do this??

Google Chrome Extensions: Get Current Page HTML (incl. Ajax or updated HTML)

In my Google Chrome extension, I need to be able to get the current page HTML, including any updated Ajax HTML (unlike the browser's View Source command, which doesn't update it).
Is there a way to get it as a string in my Extension?
Suppose my extension is a right-click context menu called "View Actual HTML Source" which should print the current HTML to the console, or maybe count the number of certain tags there. I wasn't able to find an easy answer to this.
You can get the current state of the DOM as HTML programmatically using document.documentElement.innerHTML
Or just use Developer Tools
I followed the exact solution here, and this gave me the Page Source HTML:
Getting the source HTML of the current page from chrome extension
The solution is to inject the HTML into the Popup.

Redirection with chrome extension

I'm really new to the chrome app dev part. I want to know how can I make a chrome application that will read my current URL and redirect me to another.
For instance if I am on www.stackoverflow.com and user clicks on the extension icon then it will redirect him to wwww.stackoverflow**NEW**.com
Thank you..
Follow these steps and you will be good.
Create a background script and define an entry for background script in manifest.json
In background script, define a handler on chrome.browserAction.onClicked.
Inside that handler, extract the url of current tab and check if it is the expected url, then just change the url of that tab.