Cycle through tabs , Google Chrome extensions API - google-chrome

I'm working on a slideshow extension for Google Chrome. I've created the code that fetches the right URLs and opens them in one tab each. Now I'm looking for a function in the Chrome extension API that will allow me to switch tabs programmatically, but I can't find one? Is there one and if not, what are my options?

Are you looking for the Tabs API? The update() method allows you to select a tab like this:
chrome.tabs.update(tabId, {selected: true});

The value selected has been deprecated. Use highlighted instead:
chrome.tabs.update(tabId, {highlighted: true});

Related

How to open a browser window from the Google Calendar Add-on

I'm trying to open a browser window using a Google Calendar add-on.
I've seen apps doing this, but I can't find any documents to support this option.
The methods found in Google Docs only have options to use the SpreadsheetApp, but this is not available in the calendar.
Any idea how this is achievable?
This is the expected behavior I'm looking for.
Upon clicking "NEW", a browser window should open.
var button = CardService.newTextButton()
.setText("OPEN")
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setOpenLink(CardService.newOpenLink()
.setUrl("https://google.com")
.setOpenAs(CardService.OpenAs.OVERLAY)
.setOnClose(CardService.OnClose.RELOAD_ADD_ON));
This is what I was looking for.
No need to use SpreadsheetApp

Chrome MediaRecorder API share pre-selected tab

So, here's is my doubt.
I'm using the MediaRecorder API, to make a recording of my browser's screen. I can capture the whole browser screen + audio(tab) + my microphone. Everything is working fine. But I only need to capture the screen+audio from the tab that started the recording. On that popup thats opens on google chrome, when I want to screenshare some tab or application, is it possible to show only the tab that started the screenshare? So I don't have to seek everytime the tab that I want to share.
I didn't find any information about that.
When working with the google chrome API, I see that we can capture only a tab, but outside this API, is it possible to accomplish something similar? Or is only possible to work with pre-selected tab if I develop a google chrome extension?
chrome.tabCapture.capture({audio: true, video: true}, callback);
Unfortunately you can't specify it or limit it to the current tab.
Note: Constraints never cause changes to the list of sources available
for capture by the Screen Sharing API. This ensures that web
applications can’t force the user to share specific content by
restricting the source list until only one item is left
https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API/Using_Screen_Capture

How to open a new tab after the user click on a button

I'm new in development of Google Chrome extensions.
In my extension, I want to open a new tab after the user click on a button. How I do?
https://developer.chrome.com/extensions/tabs#method-create
This took me a single Google search, a single click on one link, and a single Ctrl-F command. It might be a good idea to look for the answers yourself before posting your questions here.
You can use chrome.tabs.create() for that.
Source: Google Chrome Extensions API
You can use it like this:
<script>
// Uses the Chrome API to create a tab.
function maketab() {
chrome.tabs.create();
}
</script>
<button onclick="maketab()">Click me to make a tab!</button>

Get the active tab url in crossrider

I came to know that crossrider.com is helping us to develop extension for different browsers, while keeping the same code.
I have two questions
Question 1:
After going through docs and libraries in crossrider, I still wonder how to get the active tab url.
Question 2:
I also need to open a popup after clicking toolbar icon, similar to google chrome extension.
I came across crossrider siderbar plugin. But, I am unable to change the url for sidebar dynamically.
Do we have any other crossrider plugins which opens like an popup ?
Answer Q1: You can use our appAPI.tabs.onTabSelectionChanged(function callback([{tabId, tabUrl}])) method (soon to be documented). To keep track of the ActiveTab URL, in the callback, simply set a global variable to the callback's optional tabUrl parameter. This is currently supported in Chrome and Firefox.
Answer Q2: I'm afraid that currently there isn't a native popup plugin (your welcome to write one and submit it for consideration ;-)). However, you can configure and use jQueryUI popups from within the extension.
I need to get active tab url in IE.
If it is not possible using jquery in IE, can we use messaging api to send messages from pages to background scope, and store the active tab url in background's global variable?

Is it possible to determine a tab's opener within a Google Chrome extension?

I am looking for a way to determine a given tab's opener (parent tab) within a Google Chrome extension.
I've looked at the documention for Tab but there doesn't really seem to be anything that would yield this information. http://code.google.com/chrome/extensions/tabs.html
I've tried injecting this content script into pages (thinking I could pass the value to my background page):
alert(window.opener);
.. but it just yields null.
The best thing I've come up with so far is to keep track of the currently focused tab, and whenever a new tab is created, just assume that the focused tab is the opener/parent of the new tab. I believe this would de facto identify the parent tab correctly most of the time since background tabs rarely (are allowed to) open new pages. However, it seems kludgey and potentially inaccurate at times -- for example, if another extension opened a new tab, this method may misidentify the new tab's opener.
Update: it is now possible to reliably determine a tab's opener tab within a Chrome extension natively using the newly added webNavigation API, and specifically by hooking the onCreatedNavigationTarget event.
https://code.google.com/chrome/extensions/trunk/webNavigation.html
Chrome has added an experimental extension API which can accomplish this -- specifically webNavigation.onBeforeRetarget. http://code.google.com/chrome/extensions/experimental.webNavigation.html
However since this is still experimental (not usable in Chrome stable versions or releasable on the Chrome Web Store) I have ended up using another approach.
Basically:
In content_script.js:
chrome.extension.sendRequest({
request: {
op: "pageLoadStarted",
url: document.location.href,
referrer: document.referrer
}
});
In background.html:
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
console.log('onRequest: ' + JSON.stringify(request));
console.log(JSON.stringify(sender));
});
This approach allows me to obtain the referrer of a tab, which I can then correlate with an existing tab's url. This isn't always a one-to-one mapping, so I do some additional magic such as preferring the currently selected tab as the opener if its url matches the new tab's referrer.
This really is just a hack to approximate the functionality that would be provided more simply and accurately by webNavigation.onBeforeRetarget or window.opener.
Further investigation has revealed that onCreatedNavigationTarget() does not always fire when you think it would to indicate an opener-opened relationship.
An additional hint can sometimes be found in the Tab object returned by chrome.tabs.onCreated/onUpdated in the .openerTabId parameter.
A comprehensive solution will probably have to rely on multiple of the methods described in these answers.
port.onMessage.addListener(
function(msg) {
var tabid = port.sender.tab.openerTabId;
console.log("Received message from tab that was opened by tab id : " + tabid);
// reliably shows the tab id of the tab that opened
// the tab sending the message
});