diff --git a/src/libraries/System.Console/tests/ReadAndWrite.cs b/src/libraries/System.Console/tests/ReadAndWrite.cs
index d60fd6aa34cc04..913d85835dbb18 100644
--- a/src/libraries/System.Console/tests/ReadAndWrite.cs
+++ b/src/libraries/System.Console/tests/ReadAndWrite.cs
@@ -158,7 +158,9 @@ public static async Task OutWriteAndWriteLineOverloads()
Console.SetOut(sw);
TextWriter writer = Console.Out;
Assert.NotNull(writer);
- Assert.NotEqual(writer, sw); // the writer we provide gets wrapped
+ // Browser bypasses SyncTextWriter for faster startup
+ if (!OperatingSystem.IsBrowser())
+ Assert.NotEqual(writer, sw); // the writer we provide gets wrapped
// We just want to ensure none of these throw exceptions, we don't actually validate
// what was written.
diff --git a/src/libraries/System.Console/tests/SyncTextWriter.cs b/src/libraries/System.Console/tests/SyncTextWriter.cs
index 7d0a2f3016b64d..772e1e2b44a915 100644
--- a/src/libraries/System.Console/tests/SyncTextWriter.cs
+++ b/src/libraries/System.Console/tests/SyncTextWriter.cs
@@ -12,7 +12,8 @@
public class SyncTextWriter
{
- [Fact]
+ // Browser bypasses SyncTextWriter for faster startup
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public void SyncTextWriterLockedOnThis()
{
TextWriter oldWriter = Console.Out;
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 233d19f0d5b5f4..1ed17ee58cde75 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -22,6 +22,8 @@
true
true
true
+ true
+ $(DefineConstants);FEATURE_WASM_MANAGED_THREADS
$(DefineConstants);BIGENDIAN
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs b/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs
index a6070683047a33..d949017809f825 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs
@@ -759,7 +759,11 @@ public static TextWriter Synchronized(TextWriter writer)
{
ArgumentNullException.ThrowIfNull(writer);
+#if !TARGET_BROWSER || FEATURE_WASM_MANAGED_THREADS
return writer is SyncTextWriter ? writer : new SyncTextWriter(writer);
+#else
+ return writer;
+#endif
}
internal sealed class SyncTextWriter : TextWriter, IDisposable
diff --git a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamReader/StreamReader.cs b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamReader/StreamReader.cs
index bd455448efccaf..29677f512d9f73 100644
--- a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamReader/StreamReader.cs
+++ b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamReader/StreamReader.cs
@@ -29,7 +29,8 @@ public void ObjectClosedReadLineBaseStream()
Assert.Throws(() => sr.ReadLine());
}
- [Fact]
+ // Browser bypasses SyncTextWriter for faster startup
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public void Synchronized_NewObject()
{
using (Stream str = GetLargeStream())
diff --git a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.cs b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.cs
index 69edb13a8a1fce..cc09f1c0d2032c 100644
--- a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.cs
+++ b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.cs
@@ -7,7 +7,8 @@ namespace System.IO.Tests
{
public partial class WriteTests
{
- [Fact]
+ // Browser bypasses SyncTextWriter for faster startup
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public void Synchronized_NewObject()
{
using (Stream str = CreateStream())
diff --git a/src/libraries/System.Runtime/tests/System.IO.Tests/TextWriter/TextWriterTests.cs b/src/libraries/System.Runtime/tests/System.IO.Tests/TextWriter/TextWriterTests.cs
index 2299dc86f567db..47541635c8eef6 100644
--- a/src/libraries/System.Runtime/tests/System.IO.Tests/TextWriter/TextWriterTests.cs
+++ b/src/libraries/System.Runtime/tests/System.IO.Tests/TextWriter/TextWriterTests.cs
@@ -690,7 +690,8 @@ public void DisposeAsync_ExceptionReturnedInTask()
Assert.Same(e, vt.AsTask().Exception.InnerException);
}
- [Fact]
+ // Browser bypasses SyncTextWriter for faster startup
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public async Task FlushAsync_Precanceled()
{
Assert.Equal(TaskStatus.RanToCompletion, TextWriter.Null.FlushAsync(new CancellationToken(true)).Status);