Skip to content

Commit 07e48c2

Browse files
Crashpad info to zip folder
1 parent a91ea8f commit 07e48c2

File tree

2 files changed

+168
-4
lines changed

2 files changed

+168
-4
lines changed

diagnostics/resources/log_collection_script.ps1

Lines changed: 159 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ param(
66
[string]$OutputDirectory = "$env:TEMP",
77

88
[Parameter(Mandatory=$false)]
9-
[switch]$UseCPUProfile = $true
9+
[switch]$UseCPUProfile = $true,
10+
11+
[Parameter(Mandatory=$true)]
12+
[string]$ExeName = "ms-teams.exe",
13+
14+
[Parameter(Mandatory=$false)]
15+
[string]$userDataDir = ""
1016
)
1117

1218
# Load Windows Forms assembly for GUI
@@ -298,7 +304,8 @@ function Create-DiagnosticZip {
298304
[string]$RegistryFilePath,
299305
[string]$DirectoryFilePath,
300306
[string]$TraceFilePath,
301-
[string]$ZipPath
307+
[string]$ZipPath,
308+
[string]$WatsonMetadataFilePath = ""
302309
)
303310

304311
try {
@@ -369,6 +376,39 @@ function Create-DiagnosticZip {
369376
}
370377
}
371378

379+
# Add Crashpad folder if it exists
380+
if ($WatsonMetadataFilePath -and (Test-Path $WatsonMetadataFilePath)) {
381+
try {
382+
Write-Host "Adding Crashpad folder contents..." -ForegroundColor Cyan
383+
$crashpadFiles = Get-ChildItem -Path $WatsonMetadataFilePath -Recurse -File -ErrorAction SilentlyContinue
384+
385+
foreach ($crashpadFile in $crashpadFiles) {
386+
try {
387+
# Get relative path within Crashpad folder
388+
$relativePath = $crashpadFile.FullName.Substring($WatsonMetadataFilePath.Length + 1)
389+
$zipEntryName = "Crashpad/$relativePath".Replace("\", "/")
390+
391+
$entry = $zip.CreateEntry($zipEntryName)
392+
$entryStream = $entry.Open()
393+
394+
$fileStream = [System.IO.File]::Open($crashpadFile.FullName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
395+
$fileStream.CopyTo($entryStream)
396+
$fileStream.Close()
397+
$entryStream.Close()
398+
399+
$fileSize = $crashpadFile.Length / 1KB
400+
Write-Host " Added to zip: Crashpad/$relativePath ($([math]::Round($fileSize, 2)) KB)" -ForegroundColor Cyan
401+
}
402+
catch {
403+
Write-Host " Failed to add $($crashpadFile.Name): $($_.Exception.Message)" -ForegroundColor Red
404+
}
405+
}
406+
}
407+
catch {
408+
Write-Host " Failed to add Crashpad folder: $($_.Exception.Message)" -ForegroundColor Red
409+
}
410+
}
411+
372412
$zip.Dispose()
373413

374414
# Calculate final zip size
@@ -434,7 +474,7 @@ function Stop-WPRTrace {
434474
# Create diagnostic zip with all collected files
435475
Write-Host ""
436476
Write-Host "Creating diagnostic package..." -ForegroundColor Cyan
437-
$zipResult = Create-DiagnosticZip -RegistryFilePath $script:RegistryFilePath -DirectoryFilePath $script:DirectoryFilePath -TraceFilePath $TracePath -ZipPath $script:FinalZipPath
477+
$zipResult = Create-DiagnosticZip -RegistryFilePath $script:RegistryFilePath -DirectoryFilePath $script:DirectoryFilePath -TraceFilePath $TracePath -ZipPath $script:FinalZipPath -WatsonMetadataFilePath $script:WatsonMetadataFilePath
438478

439479
if ($zipResult) {
440480
Write-Host "All diagnostic files have been packaged and saved to: $zipResult" -ForegroundColor Green
@@ -700,6 +740,111 @@ function Export-EdgeUpdateRegistry {
700740
}
701741
}
702742

743+
# Function to get watson_metadata file from Crashpad folder
744+
function Get-WatsonMetadataFile {
745+
param(
746+
[Parameter(Mandatory=$false)]
747+
[array]$UserDataFolders = @(),
748+
749+
[Parameter(Mandatory=$false)]
750+
[string]$UserDataDir = ""
751+
)
752+
753+
try {
754+
$folderToCheck = ""
755+
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
761+
$folderToCheck = $UserDataDir
762+
}
763+
764+
if (-not [string]::IsNullOrWhiteSpace($folderToCheck)) {
765+
$crashpadFolder = Join-Path $folderToCheck "Crashpad"
766+
767+
if (Test-Path $crashpadFolder) {
768+
Write-Host "Checking Crashpad folder: $crashpadFolder" -ForegroundColor Cyan
769+
Write-Host "Found Crashpad folder: $crashpadFolder" -ForegroundColor Green
770+
return $crashpadFolder
771+
}
772+
else {
773+
Write-Host "Crashpad folder not found: $crashpadFolder" -ForegroundColor Yellow
774+
}
775+
}
776+
else {
777+
Write-Host "No user data folder available to check for watson_metadata" -ForegroundColor Yellow
778+
}
779+
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
841+
}
842+
catch {
843+
Write-Host "Error getting WebView2 user data folders: $($_.Exception.Message)" -ForegroundColor Red
844+
return @()
845+
}
846+
}
847+
703848
# Collect installer logs.
704849
$registryResult = Export-EdgeUpdateRegistry -OutputDirectory $OutputDirectory
705850
Write-Host ""
@@ -721,5 +866,16 @@ Write-Host "Directory file: $directoryResult" -ForegroundColor Yellow
721866
Write-Host "Zip destination: $ZipPath" -ForegroundColor Yellow
722867
Write-Host ""
723868

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
873+
}
874+
Write-Host ""
875+
876+
# Look for watson_metadata file in Crashpad foldercmd
877+
$script:WatsonMetadataFilePath = Get-WatsonMetadataFile -UserDataFolders $userDataFolders -UserDataDir $userDataDir
878+
Write-Host ""
879+
724880
# Start WPR tracing automatically
725881
StartWPR -OutputDirectory $OutputDirectory -OutPath $OutPath -UseCPUProfile $UseCPUProfile

diagnostics/script.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The script automates collection of commonly requested WebView2 diagnostic data
99
3. Run the script by executing:
1010

1111
```
12-
.\log_collection_script.ps1
12+
.\log_collection_script.ps1 -ExeName <exe-name>
1313
```
1414

1515
The script will collect some registry keys and directory listings, start a WPR trace, and display a window similar to the image below.
@@ -27,6 +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
3031
7. Provide the resulting ZIP file to the WebView2 support team for analysis.
3132

3233
**Optional**
@@ -38,6 +39,13 @@ To specify a different output directory for the ZIP file, provide the `ZipPath`
3839
3940
```
4041

42+
Sometimes if the script is not able to find the crashpad folder, user can use the `userDataDir` parameter to pass the user data directory to the script.
43+
44+
```
45+
.\log_collection_script.ps1 -userDataDir <absolute-path-to-user-data-dir>
46+
```
47+
48+
4149
**Troubleshooting**
4250

4351
If you encounter an execution policy error when running the script:

0 commit comments

Comments
 (0)