Skip to content

Commit 51c38bd

Browse files
update script to collect crashpad
1 parent 07e48c2 commit 51c38bd

File tree

2 files changed

+77
-83
lines changed

2 files changed

+77
-83
lines changed

diagnostics/resources/log_collection_script.ps1

Lines changed: 76 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ param(
88
[Parameter(Mandatory=$false)]
99
[switch]$UseCPUProfile = $true,
1010

11-
[Parameter(Mandatory=$true)]
12-
[string]$ExeName = "ms-teams.exe",
11+
[Parameter(Mandatory=$false)]
12+
[string]$ExeName = "",
1313

1414
[Parameter(Mandatory=$false)]
1515
[string]$userDataDir = ""
@@ -740,108 +740,95 @@ function Export-EdgeUpdateRegistry {
740740
}
741741
}
742742

743-
# Function to get watson_metadata file from Crashpad folder
744-
function Get-WatsonMetadataFile {
743+
# Function to get user data folders from WebView2 processes
744+
function Get-WebView2UserDataFolder {
745745
param(
746-
[Parameter(Mandatory=$false)]
747-
[array]$UserDataFolders = @(),
746+
[Parameter(Mandatory=$true)]
747+
[string]$ExeName,
748748

749749
[Parameter(Mandatory=$false)]
750750
[string]$UserDataDir = ""
751751
)
752752

753753
try {
754+
# Look for Crashpad folder
755+
$crashpadFolder = ""
754756
$folderToCheck = ""
757+
$uniqueUserDataFolders = @()
755758

756-
if ($UserDataFolders.Count -gt 0) {
757-
$folderToCheck = $UserDataFolders[0]
758-
}
759-
elseif (-not [string]::IsNullOrWhiteSpace($UserDataDir)) {
760-
Write-Host "No user data folders found from processes, using provided userDataDir: $UserDataDir" -ForegroundColor Cyan
759+
if (-not [string]::IsNullOrWhiteSpace($UserDataDir)) {
760+
Write-Host "Using provided userDataDir: $UserDataDir" -ForegroundColor Cyan
761761
$folderToCheck = $UserDataDir
762762
}
763+
else {
764+
Write-Host "Searching for msedgewebview2.exe processes with exe name: $ExeName" -ForegroundColor Green
765+
766+
# Get all msedgewebview2.exe processes with their command lines
767+
$processes = Get-CimInstance Win32_Process -Filter "Name = 'msedgewebview2.exe'" -ErrorAction SilentlyContinue
768+
769+
if (-not $processes) {
770+
Write-Host "No msedgewebview2.exe processes found" -ForegroundColor Yellow
771+
return @{ UserDataFolders = @(); CrashpadFolder = "" }
772+
}
773+
774+
$userDataFolders = @()
775+
776+
foreach ($process in $processes) {
777+
$commandLine = $process.CommandLine
778+
779+
if ($commandLine) {
780+
# Check if command line contains required parameters
781+
if ($commandLine -match '--embedded-browser-webview=1' -and
782+
$commandLine -match "--webview-exe-name=$([regex]::Escape($ExeName))") {
783+
784+
Write-Host " Process ID $($process.ProcessId) matches criteria" -ForegroundColor Cyan
785+
786+
# Extract --user-data-dir value
787+
# Pattern handles: --user-data-dir="path" or --user-data-dir=path
788+
if ($commandLine -match '--user-data-dir=(?:"([^"]+)"|([^\s]+))') {
789+
$userDataFolder = if ($matches[1]) { $matches[1] } else { $matches[2] }
790+
$userDataFolders += $userDataFolder
791+
}
792+
}
793+
}
794+
}
795+
796+
# Get unique values only
797+
$uniqueUserDataFolders = $userDataFolders | Select-Object -Unique
798+
799+
if ($uniqueUserDataFolders.Count -eq 0) {
800+
Write-Host "No matching processes found with the specified criteria" -ForegroundColor Yellow
801+
}
802+
else {
803+
Write-Host "Total user data folders found: $($userDataFolders.Count) (unique: $($uniqueUserDataFolders.Count))" -ForegroundColor Green
804+
}
805+
806+
if ($uniqueUserDataFolders.Count -gt 0) {
807+
$folderToCheck = $uniqueUserDataFolders[0]
808+
}
809+
}
763810

764811
if (-not [string]::IsNullOrWhiteSpace($folderToCheck)) {
765812
$crashpadFolder = Join-Path $folderToCheck "Crashpad"
766813

767814
if (Test-Path $crashpadFolder) {
768815
Write-Host "Checking Crashpad folder: $crashpadFolder" -ForegroundColor Cyan
769816
Write-Host "Found Crashpad folder: $crashpadFolder" -ForegroundColor Green
770-
return $crashpadFolder
771817
}
772818
else {
773819
Write-Host "Crashpad folder not found: $crashpadFolder" -ForegroundColor Yellow
820+
$crashpadFolder = ""
774821
}
775822
}
776823
else {
777-
Write-Host "No user data folder available to check for watson_metadata" -ForegroundColor Yellow
824+
Write-Host "No user data folder available to check for Crashpad" -ForegroundColor Yellow
778825
}
779826

780-
return ""
781-
}
782-
catch {
783-
Write-Host "Error searching for watson_metadata file: $($_.Exception.Message)" -ForegroundColor Red
784-
return ""
785-
}
786-
}
787-
788-
# Function to get user data folders from WebView2 processes
789-
function Get-WebView2UserDataFolder {
790-
param(
791-
[Parameter(Mandatory=$true)]
792-
[string]$ExeName
793-
)
794-
795-
try {
796-
Write-Host "Searching for msedgewebview2.exe processes with exe name: $ExeName" -ForegroundColor Green
797-
798-
# Get all msedgewebview2.exe processes with their command lines
799-
$processes = Get-CimInstance Win32_Process -Filter "Name = 'msedgewebview2.exe'" -ErrorAction SilentlyContinue
800-
801-
if (-not $processes) {
802-
Write-Host "No msedgewebview2.exe processes found" -ForegroundColor Yellow
803-
return @()
804-
}
805-
806-
Write-Host "Found $($processes.Count) msedgewebview2.exe process(es)" -ForegroundColor Cyan
807-
808-
$userDataFolders = @()
809-
810-
foreach ($process in $processes) {
811-
$commandLine = $process.CommandLine
812-
813-
if ($commandLine) {
814-
# Check if command line contains required parameters
815-
if ($commandLine -match '--embedded-browser-webview=1' -and
816-
$commandLine -match "--webview-exe-name=$([regex]::Escape($ExeName))") {
817-
818-
Write-Host " Process ID $($process.ProcessId) matches criteria" -ForegroundColor Cyan
819-
820-
# Extract --user-data-dir value
821-
# Pattern handles: --user-data-dir="path" or --user-data-dir=path
822-
if ($commandLine -match '--user-data-dir=(?:"([^"]+)"|([^\s]+))') {
823-
$userDataFolder = if ($matches[1]) { $matches[1] } else { $matches[2] }
824-
$userDataFolders += $userDataFolder
825-
}
826-
}
827-
}
828-
}
829-
830-
# Get unique values only
831-
$uniqueUserDataFolders = $userDataFolders | Select-Object -Unique
832-
833-
if ($uniqueUserDataFolders.Count -eq 0) {
834-
Write-Host "No matching processes found with the specified criteria" -ForegroundColor Yellow
835-
}
836-
else {
837-
Write-Host "Total user data folders found: $($userDataFolders.Count) (unique: $($uniqueUserDataFolders.Count))" -ForegroundColor Green
838-
}
839-
840-
return $uniqueUserDataFolders
827+
return @{ UserDataFolders = $uniqueUserDataFolders; CrashpadFolder = $crashpadFolder }
841828
}
842829
catch {
843830
Write-Host "Error getting WebView2 user data folders: $($_.Exception.Message)" -ForegroundColor Red
844-
return @()
831+
return @{ UserDataFolders = @(); CrashpadFolder = "" }
845832
}
846833
}
847834

@@ -866,15 +853,22 @@ Write-Host "Directory file: $directoryResult" -ForegroundColor Yellow
866853
Write-Host "Zip destination: $ZipPath" -ForegroundColor Yellow
867854
Write-Host ""
868855

869-
$userDataFolders = Get-WebView2UserDataFolder -ExeName $ExeName
870-
Write-Host "User data folders found: $($userDataFolders.Count)" -ForegroundColor Yellow
871-
foreach ($folder in $userDataFolders) {
872-
Write-Host " $folder" -ForegroundColor Yellow
856+
$result = @{ UserDataFolders = @(); CrashpadFolder = "" }
857+
if (-not [string]::IsNullOrWhiteSpace($ExeName)) {
858+
$result = Get-WebView2UserDataFolder -ExeName $ExeName -UserDataDir $userDataDir
859+
Write-Host "User data folders found: $($result.UserDataFolders.Count)" -ForegroundColor Yellow
860+
foreach ($folder in $result.UserDataFolders) {
861+
Write-Host " $folder" -ForegroundColor Yellow
862+
}
863+
Write-Host ""
864+
}
865+
else {
866+
Write-Host "ExeName not provided, skipping user data folder detection" -ForegroundColor Yellow
867+
Write-Host ""
873868
}
874-
Write-Host ""
875869

876-
# Look for watson_metadata file in Crashpad foldercmd
877-
$script:WatsonMetadataFilePath = Get-WatsonMetadataFile -UserDataFolders $userDataFolders -UserDataDir $userDataDir
870+
# Set Crashpad folder path
871+
$script:WatsonMetadataFilePath = $result.CrashpadFolder
878872
Write-Host ""
879873

880874
# Start WPR tracing automatically

diagnostics/script.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The script will collect some registry keys and directory listings, start a WPR t
2727
- msedge_installer_Temp.log (*optional*)
2828
- msedge_installer_SystemTemp.log (*optional*)
2929
- msedge_installer_SystemTemp2.log (*optional*)
30-
- Crashpad folder
30+
- Crashpad folder (if ExeName or userDataDir provided)
3131
7. Provide the resulting ZIP file to the WebView2 support team for analysis.
3232

3333
**Optional**

0 commit comments

Comments
 (0)