Created
July 20, 2024 20:06
-
-
Save SkyN9ne/69b9b7ba8c4e49efb9b5aacefbf3f3f4 to your computer and use it in GitHub Desktop.
edge:// internal suspicious files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2023 The Chromium Authors | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
import "./strings.m.js"; | |
import { | |
assertNotReached | |
} from "edge://resources/js/assert.js"; | |
import { | |
loadTimeData | |
} from "edge://resources/js/load_time_data.js"; | |
import { | |
getRequiredElement | |
} from "edge://resources/js/util.js"; | |
import { | |
WebAppInternalsHandler | |
} from "./web_app_internals.mojom-webui.js"; | |
const webAppInternalsHandler = WebAppInternalsHandler.getRemote(); | |
const debugInfoAsJsonString = webAppInternalsHandler.getDebugInfoAsJsonString().then((response => response.result)); | |
const iwaInstallButton = getRequiredElement("iwa-install-button"); | |
const iwaInstallUrl = getRequiredElement("iwa-install-url"); | |
const iwaSelectFileButton = getRequiredElement("iwa-select-bundle"); | |
const iwaSearchForUpdatesButton = getRequiredElement("iwa-search-for-updates"); | |
function originToText(origin) { | |
if (origin.host.length === 0) { | |
return "null" | |
} | |
let result = origin.scheme + "://" + origin.host; | |
if (!(origin.scheme === "https" && origin.port === 443) && !(origin.scheme === "http" && origin.port === 80)) { | |
result += ":" + origin.port | |
} | |
return result | |
} | |
function filePathToText(filePath) { | |
if (typeof filePath.path === "string") { | |
return filePath.path | |
} | |
const decoder = new TextDecoder("utf-16"); | |
const buffer = new Uint16Array(filePath.path); | |
return decoder.decode(buffer) | |
} | |
getRequiredElement("copy-button").addEventListener("click", (async () => { | |
navigator.clipboard.writeText(await debugInfoAsJsonString) | |
})); | |
getRequiredElement("download-button").addEventListener("click", (async () => { | |
const url = URL.createObjectURL(new Blob([await debugInfoAsJsonString], { | |
type: "application/json" | |
})); | |
const a = document.createElement("a"); | |
a.href = url; | |
a.download = "web_app_internals.json"; | |
a.click(); | |
URL.revokeObjectURL(url) | |
})); | |
function iwaInstallStateUpdate() { | |
iwaInstallButton.disabled = iwaInstallUrl.value.length === 0 | |
} | |
async function iwaInstallSubmit() { | |
iwaInstallButton.disabled = true; | |
const iwaInstallMessageDiv = getRequiredElement("iwa-install-message-div"); | |
let valid = false; | |
try { | |
new URL(iwaInstallUrl.value); | |
valid = iwaInstallUrl.value.startsWith("http:") || iwaInstallUrl.value.startsWith("https:") | |
} catch (_) {} | |
if (!valid) { | |
iwaInstallMessageDiv.innerText = `Installing IWA: ${iwaInstallUrl.value} is not a valid URL`; | |
iwaInstallStateUpdate(); | |
return | |
} | |
iwaInstallMessageDiv.innerText = `Installing IWA: ${iwaInstallUrl.value}...`; | |
const location = { | |
url: iwaInstallUrl.value | |
}; | |
const installFromDevProxy = await webAppInternalsHandler.installIsolatedWebAppFromDevProxy(location); | |
if (installFromDevProxy.result.success) { | |
iwaInstallMessageDiv.innerText = `Installing IWA: ${iwaInstallUrl.value} successfully installed.`; | |
iwaInstallUrl.value = ""; | |
iwaInstallStateUpdate(); | |
return | |
} | |
iwaInstallMessageDiv.innerText = `Installing IWA: ${iwaInstallUrl.value} failed to install: ${installFromDevProxy.result.error}`; | |
iwaInstallStateUpdate() | |
} | |
iwaInstallUrl.addEventListener("enter", iwaInstallSubmit); | |
iwaInstallButton.addEventListener("click", iwaInstallSubmit); | |
function updateIwaInstallButtonState(event) { | |
if (event.key === "Enter") { | |
event.preventDefault(); | |
iwaInstallSubmit(); | |
return | |
} | |
iwaInstallStateUpdate() | |
} | |
iwaInstallUrl.addEventListener("keyup", updateIwaInstallButtonState); | |
iwaInstallStateUpdate(); | |
async function iwaSelectFile() { | |
const iwaInstallMessageDiv = getRequiredElement("iwa-install-message-div"); | |
iwaInstallMessageDiv.innerText = `Installing IWA from bundle...`; | |
const installFromDevBundle = await webAppInternalsHandler.selectFileAndInstallIsolatedWebAppFromDevBundle(); | |
if (installFromDevBundle.result.success) { | |
iwaInstallMessageDiv.innerText = `Installing IWA: successfully installed.`; | |
return | |
} | |
iwaInstallMessageDiv.innerText = `Installing IWA: failed to install: ${installFromDevBundle.result.error}` | |
} | |
iwaSelectFileButton.addEventListener("click", iwaSelectFile); | |
async function iwaSearchForUpdates() { | |
const messageDiv = getRequiredElement("iwa-update-discovery-message-div"); | |
messageDiv.innerText = `Queueing update discovery tasks...`; | |
const { | |
result: result | |
} = await webAppInternalsHandler.searchForIsolatedWebAppUpdates(); | |
messageDiv.innerText = result | |
} | |
iwaSearchForUpdatesButton.addEventListener("click", iwaSearchForUpdates); | |
function formatDevModeLocation(location) { | |
if (location.proxyOrigin) { | |
return originToText(location.proxyOrigin) | |
} | |
if (location.bundlePath) { | |
return filePathToText(location.bundlePath) | |
} | |
assertNotReached() | |
} | |
document.addEventListener("DOMContentLoaded", (async () => { | |
getRequiredElement("json").innerText = await debugInfoAsJsonString; | |
if (loadTimeData.getBoolean("experimentalAreIwasEnabled")) { | |
getRequiredElement("iwa-div").style.display = ""; | |
if (loadTimeData.getBoolean("experimentalIsIwaDevModeEnabled")) { | |
getRequiredElement("iwa-install-div").style.display = ""; | |
const devModeAppList = getRequiredElement("iwa-dev-mode-app-list"); | |
const { | |
apps: devModeApps | |
} = await webAppInternalsHandler.getIsolatedWebAppDevModeAppInfo(); | |
for (const devModeApp of devModeApps) { | |
const li = document.createElement("li"); | |
li.innerText = `${devModeApp.name} (${devModeApp.installedVersion}) → ${formatDevModeLocation(devModeApp.location)}`; | |
const updateMsg = document.createElement("p"); | |
const updateBtn = document.createElement("button"); | |
updateBtn.className = "iwa-update-btn"; | |
updateBtn.innerText = "Perform update now"; | |
updateBtn.onclick = async () => { | |
const oldText = updateBtn.innerText; | |
try { | |
updateBtn.disabled = true; | |
updateBtn.innerText = "Performing update... (close the IWA if it is currently open!)"; | |
if (devModeApp.location.bundlePath) { | |
const { | |
result: result | |
} = await webAppInternalsHandler.selectFileAndUpdateIsolatedWebAppFromDevBundle(devModeApp.appId); | |
updateMsg.innerText = result | |
} else if (devModeApp.location.proxyOrigin) { | |
const { | |
result: result | |
} = await webAppInternalsHandler.updateDevProxyIsolatedWebApp(devModeApp.appId); | |
updateMsg.innerText = result | |
} else { | |
assertNotReached() | |
} | |
} finally { | |
updateBtn.innerText = oldText; | |
updateBtn.disabled = false | |
} | |
}; | |
li.appendChild(updateBtn); | |
li.appendChild(updateMsg); | |
devModeAppList.appendChild(li) | |
} | |
getRequiredElement("iwa-dev-mode-updates").style.display = "" | |
} | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment