MCPcopy
hub / github.com/philc/vimium / goto

Function goto

background_scripts/marks.js:49–76  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

47// we create a new one. Whichever of those we do, we then set the scroll position to the original
48// scroll position.
49export async function goto(req) {
50 const vimiumSecret = (await chrome.storage.session.get("vimiumSecret"))["vimiumSecret"];
51 const key = getLocationKey(req.markName);
52 const items = await chrome.storage.local.get(key);
53 const markInfo = items[key];
54 if (markInfo.vimiumSecret !== vimiumSecret) {
55 // This is a different Vimium instantiation, so markInfo.tabId is definitely out of date.
56 Utils.debugLog("marks: vimiumSecret is incorrect.");
57 await focusOrLaunch(markInfo, req);
58 } else {
59 // Check whether markInfo.tabId still exists. According to
60 // https://developer.chrome.com/extensions/tabs, tab Ids are unqiue within a Chrome
61 // session. So, if we find a match, we can use it.
62 let tab;
63 // This will throw an error if the tab doesn't exist.
64 try {
65 tab = await chrome.tabs.get(markInfo.tabId);
66 } catch {
67 // Swallow.
68 }
69 const originalTabStillExists = tab?.url && (markInfo.url === getBaseUrl(tab.url));
70 if (originalTabStillExists) {
71 await gotoPositionInTab(markInfo);
72 } else {
73 await focusOrLaunch(markInfo, req);
74 }
75 }
76}
77
78// Focus an existing tab and scroll to the given position within it.
79async function gotoPositionInTab({ tabId, scrollX, scrollY }) {

Callers

nothing calls this directly

Calls 5

focusOrLaunchFunction · 0.85
getBaseUrlFunction · 0.85
gotoPositionInTabFunction · 0.85
getMethod · 0.80
getLocationKeyFunction · 0.70

Tested by

no test coverage detected