Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions TMWebDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,11 @@ def set_session(self, url_pattern: str) -> bool:

def jump(self, url, timeout=10): self.execute_js(f"window.location.href='{url}'", timeout=timeout)

def newtab(self, url=None, active=True):
"""Open a new browser tab via bridge extension (chrome.tabs.create)."""
import json
code = json.dumps({"cmd": "tabs", "method": "create", "url": url or "about:blank", "active": active})
return self.execute_js(code)

if __name__ == "__main__":
driver = TMWebDriver(host='127.0.0.1', port=18765)
6 changes: 6 additions & 0 deletions assets/tmwd_cdp_bridge/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ async function handleExtMessage(msg, sender) {
const tab = await chrome.tabs.update(msg.tabId, { active: true });
await chrome.windows.update(tab.windowId, { focused: true });
return { ok: true };
} else if (msg.method === 'create') {
const opts = {};
if (msg.url) opts.url = msg.url;
if (msg.active !== undefined) opts.active = msg.active;
const tab = await chrome.tabs.create(opts);
return { ok: true, data: { id: tab.id, url: tab.url || (msg.url || 'about:blank'), title: tab.title || '', windowId: tab.windowId } };
} else {
const tabs = (await chrome.tabs.query({})).filter(t => isScriptable(t.url));
const data = tabs.map(t => ({ id: t.id, url: t.url, title: t.title, active: t.active, windowId: t.windowId }));
Expand Down