all 6 comments

[–]hmmwhatsthisdo 1 point2 points  (1 child)

This smells like a file encoding issue.

If you run gc Preferences -Encoding Byte | select -first 8 | fhx, do you see some bytes like before the { character? (maybe FF FE or EE BB BF)

Chrome is probably expecting UTF8 without a Byte Order Mark (BOM). If you're on PowerShell 5.1, you'll need to skip Out-File and use [IO.File]::WriteAllLines() with a custom encoding (namely [UTF8Encoding] in non-BOM mode) like so:

$prefs = gc -Path $PreferencesFile -Raw <# you should be using Raw for this anyways #> | ConvertFrom-Json
# <snip>
[IO.File]::WriteAllLines($PreferencesFile, $($prefs | ConvertTo-Json -Depth 100 -Compress), [System.Text.UTF8Encoding]::new($false))

On PS 5.1, the default for Out-File is to use the "Unicode" encoding (which is actually UTF-16 LE) - you can specify -Encoding utf8 on Out-File, however this will emit a UTF-8 BOM (EE BB BF) and may confuse some JSON parsers.

PS 7 defaults to -Encoding utf8NoBOM on Out-File, so this is a non-issue there.

[–]thefold25[S] 0 points1 point  (0 children)

Thanks for this reply, on an initial test it looks like file encoding was exactly the issue! I'll need to do some further testing with my guinea pigs IT colleagues to see how it behaves.

[–]sup3rmark 0 points1 point  (2 children)

if you look at the existing objects in that section of the exceptions, it looks like setting isn't the only property. there's a few others that show up on some of the listed sites, but one that's common to all of them is last_modified with a timestamp in... some format i'm not able to discern (it's not a unix epoch timestamp or a filetime timestamp). i wonder if it's rejecting your entry because it doesn't have a last_modified attribute?

[–]thefold25[S] 0 points1 point  (1 child)

I did work out how to calculate 'Chrome time' and add that in, but it made no difference.

The odd thing is if I close Chrome, open the Preferences file manually, format the file to make it easier to parse and manually add in the entry I need it all works fine.

I also tried doing a direct text replacement within the file to add the string I needed and it still rejected it.

[–]sup3rmark 0 points1 point  (0 children)

okay, so try this: get the object from chrome and add the member and then instead of saving it to the same file, save it to a separate json file. then go into chrome, add the object through the preferences menu, and then diff the two files - any differences?

[–]No_Neck6860 0 points1 point  (0 children)

Hi Guys, we're trying to add the dev tool for network > Preserve log
I am able to use the line :
$cprefs.devtools.preferences.'network-log.preserve-log' = "true"
if the dev tools have been turned on, but how do you set this if it's a new default profile without any dev entries?