MCPcopy Create free account
hub / github.com/MicrosoftEdge/WebView2Browser / HandleTabNavCompleted

Method HandleTabNavCompleted

BrowserWindow.cpp:575–676  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573}
574
575HRESULT BrowserWindow::HandleTabNavCompleted(size_t tabId, ICoreWebView2* webview, ICoreWebView2NavigationCompletedEventArgs* args)
576{
577 std::wstring getTitleScript(
578 // Look for a title tag
579 L"(() => {"
580 L" const titleTag = document.getElementsByTagName('title')[0];"
581 L" if (titleTag) {"
582 L" return titleTag.innerHTML;"
583 L" }"
584 // No title tag, look for the file name
585 L" pathname = window.location.pathname;"
586 L" var filename = pathname.split('/').pop();"
587 L" if (filename) {"
588 L" return filename;"
589 L" }"
590 // No file name, look for the hostname
591 L" const hostname = window.location.hostname;"
592 L" if (hostname) {"
593 L" return hostname;"
594 L" }"
595 // Fallback: let the UI use a generic title
596 L" return '';"
597 L"})();"
598 );
599
600 std::wstring getFaviconURI(
601 L"(() => {"
602 // Let the UI use a fallback favicon
603 L" let faviconURI = '';"
604 L" let links = document.getElementsByTagName('link');"
605 // Test each link for a favicon
606 L" Array.from(links).map(element => {"
607 L" let rel = element.rel;"
608 // Favicon is declared, try to get the href
609 L" if (rel && (rel == 'shortcut icon' || rel == 'icon')) {"
610 L" if (!element.href) {"
611 L" return;"
612 L" }"
613 // href to icon found, check it's full URI
614 L" try {"
615 L" let urlParser = new URL(element.href);"
616 L" faviconURI = urlParser.href;"
617 L" } catch(e) {"
618 // Try prepending origin
619 L" let origin = window.location.origin;"
620 L" let faviconLocation = `${origin}/${element.href}`;"
621 L" try {"
622 L" urlParser = new URL(faviconLocation);"
623 L" faviconURI = urlParser.href;"
624 L" } catch (e2) {"
625 L" return;"
626 L" }"
627 L" }"
628 L" }"
629 L" });"
630 L" return faviconURI;"
631 L"})();"
632 );

Callers 1

InitMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected