Opens a new tab in the Chrome browser and navigates to the specified URL. This endpoint allows an agent to create a new browser tab and load a specific website in that tab.
Note: Chrome must be started with the POST /tools-api/system/open-chrome
action first before using this endpoint. The newly created tab becomes the active tab after creation.
Parameter | Type | Required | Description |
---|---|---|---|
url | string | Yes | The URL to navigate to in the new tab. Must be a valid absolute URL (e.g., "https://www.google.com"). The system will automatically add "https://" if no protocol is specified. If not provided or empty, the new tab will open with "about:blank". |
{ "url": "https://www.google.com" }
Parameter | Type | Description |
---|---|---|
success | boolean | Indicates whether the operation was successful. |
message | string | A human-readable message describing the result of the operation. For successful operations, this will indicate that a new tab was created and navigated to the specified URL. For failures, it will contain error information. |
timestamp | datetime | The time when the response was generated. |
{ "success": true, "message": "newtab executed at https://www.google.com", "timestamp": "2023-10-26T14:23:45.123Z" }
{ "success": false, "message": "Failed to create new tab: No active browser instance", "timestamp": "2023-10-26T14:23:45.123Z" }
import requests
import json
from datetime import datetime
class ToolsServerClient:
def __init__(self, api_key, base_url="http://localhost:54321"):
self.base_url = base_url
self.headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
def open_new_tab(self, url):
"""
Opens a new tab in Chrome and navigates to the specified URL.
Args:
url (str): The URL to navigate to in the new tab.
Returns:
dict: The response from the server containing success status and message.
"""
endpoint = "/tools-api/chrome/new-tab"
payload = {
"url": url
}
response = requests.post(
f"{self.base_url}{endpoint}",
headers=self.headers,
data=json.dumps(payload)
)
return response.json()
# Example usage
client = ToolsServerClient("your_api_key_here")
result = client.open_new_tab("https://www.google.com")
print(f"Success: {result['success']}")
print(f"Message: {result['message']}")
print(f"Timestamp: {result['timestamp']}")
import axios from 'axios';
interface NewTabRequest {
url: string;
}
interface ActionResponse {
success: boolean;
message: string;
timestamp: string;
}
class ToolsServerClient {
private baseUrl: string;
private headers: Record;
constructor(apiKey: string, baseUrl: string = 'http://localhost:54321') {
this.baseUrl = baseUrl;
this.headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
};
}
/**
* Opens a new tab in Chrome and navigates to the specified URL.
*
* @param url - The URL to navigate to in the new tab
* @returns Promise resolving to the action response
*/
async openNewTab(url: string): Promise {
const endpoint = '/tools-api/chrome/new-tab';
const payload: NewTabRequest = {
url: url
};
try {
const response = await axios.post(
`${this.baseUrl}${endpoint}`,
payload,
{ headers: this.headers }
);
return response.data;
} catch (error) {
if (axios.isAxiosError(error) && error.response) {
throw new Error(`Failed to open new tab: ${error.response.data.message || error.message}`);
}
throw error;
}
}
}
// Example usage
async function example() {
const client = new ToolsServerClient('your_api_key_here');
try {
const result = await client.openNewTab('https://www.google.com');
console.log(`Success: ${result.success}`);
console.log(`Message: ${result.message}`);
console.log(`Timestamp: ${result.timestamp}`);
} catch (error) {
console.error(`Error: ${error.message}`);
}
}
example();
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class ToolsServerClient
{
private readonly HttpClient _httpClient;
private readonly string _baseUrl;
public ToolsServerClient(string apiKey, string baseUrl = "http://localhost:54321")
{
_baseUrl = baseUrl;
_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
}
///
/// Opens a new tab in Chrome and navigates to the specified URL.
///
/// The URL to navigate to in the new tab
/// Response containing success status and message
public async Task OpenNewTabAsync(string url)
{
var request = new ChromeNewTabRequest
{
Url = url
};
var jsonContent = JsonSerializer.Serialize(request);
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{_baseUrl}/tools-api/chrome/new-tab", content);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize(responseBody, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
}
}
public class ChromeNewTabRequest
{
public string Url { get; set; }
}
public class ActionResponse
{
public bool Success { get; set; }
public string Message { get; set; }
public DateTime Timestamp { get; set; }
}
// Example usage
class Program
{
static async Task Main()
{
var client = new ToolsServerClient("your_api_key_here");
try
{
var result = await client.OpenNewTabAsync("https://www.google.com");
Console.WriteLine($"Success: {result.Success}");
Console.WriteLine($"Message: {result.Message}");
Console.WriteLine($"Timestamp: {result.Timestamp}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
This example opens a new tab in Chrome and navigates to Google's search page.
{ "url": "https://www.google.com" }
This example opens a new tab in Chrome and navigates to YouTube.
{ "url": "https://www.youtube.com" }
This example opens a new tab in Chrome and performs a Google search for "windows automation API".
{ "url": "https://www.google.com/search?q=windows+automation+API" }