MCPcopy
hub / github.com/pinokiocomputer/pinokio / selectTargetFrame

Function selectTargetFrame

full.js:961–1089  ·  view source on GitHub ↗
(webContents, payload = {})

Source from the content-addressed store, hash-verified

959}
960
961const selectTargetFrame = (webContents, payload = {}) => {
962 if (!webContents || !webContents.mainFrame) {
963 inspectorMainLog('no-webcontents', {})
964 return null
965 }
966 const frames = flattenFrameTree(webContents.mainFrame, [])
967 if (!frames.length) {
968 inspectorMainLog('no-frames', { webContentsId: webContents.id })
969 return null
970 }
971 inspectorMainLog('incoming', {
972 frameUrl: payload.frameUrl || null,
973 frameName: payload.frameName || null,
974 frameNodeId: payload.frameNodeId || null,
975 frameCount: frames.length,
976 })
977
978 const canonicalUrl = normalizeInspectorUrl(payload.frameUrl)
979 const relativeOrdinal = typeof payload.candidateRelativeOrdinal === 'number' ? payload.candidateRelativeOrdinal : null
980 const globalOrdinal = typeof payload.frameIndex === 'number' ? payload.frameIndex : null
981 const canonicalFrameName = typeof payload.frameName === 'string' && payload.frameName.trim() ? payload.frameName.trim() : null
982 const canonicalFrameNodeId = typeof payload.frameNodeId === 'string' && payload.frameNodeId.trim() ? payload.frameNodeId.trim() : null
983
984 if (canonicalFrameName || canonicalFrameNodeId) {
985 inspectorMainLog('identifier-search', {
986 frameName: canonicalFrameName || null,
987 frameNodeId: canonicalFrameNodeId || null,
988 names: frames.map((entry) => entry.name || null).slice(0, 12),
989 })
990
991 let identifierMatch = null
992 if (canonicalFrameNodeId) {
993 identifierMatch = frames.find((entry) => entry && entry.name === canonicalFrameNodeId) || null
994 if (identifierMatch) {
995 const normalizedUrl = normalizeInspectorUrl(identifierMatch.url || '')
996 if (canonicalUrl && (!normalizedUrl || !urlsRoughlyMatch(canonicalUrl, normalizedUrl))) {
997 const descendant = findDescendantByUrl(identifierMatch.frame, canonicalUrl)
998 if (descendant) {
999 inspectorMainLog('identifier-match-node-descendant', {
1000 index: frames.indexOf(identifierMatch),
1001 name: identifierMatch.name || null,
1002 url: identifierMatch.url || null,
1003 descendantUrl: normalizeInspectorUrl(descendant.url || ''),
1004 })
1005 return descendant
1006 }
1007 }
1008 inspectorMainLog('identifier-match-node', {
1009 index: frames.indexOf(identifierMatch),
1010 name: identifierMatch.name || null,
1011 url: identifierMatch.url || null,
1012 })
1013 return identifierMatch.frame
1014 }
1015 }
1016
1017 if (canonicalFrameName) {
1018 identifierMatch = frames.find((entry) => entry && entry.name === canonicalFrameName) || null

Callers 1

startInspectorSessionFunction · 0.85

Calls 5

inspectorMainLogFunction · 0.85
flattenFrameTreeFunction · 0.85
normalizeInspectorUrlFunction · 0.85
urlsRoughlyMatchFunction · 0.85
findDescendantByUrlFunction · 0.85

Tested by

no test coverage detected