| 
12 | 12 | namespace PuppeteerSharp  | 
13 | 13 | {  | 
14 | 14 |     /// <inheritdoc cref="IExecutionContext"/>  | 
15 |  | -    public sealed class ExecutionContext : IExecutionContext, IDisposable, IAsyncDisposable  | 
 | 15 | +    public sealed partial class ExecutionContext : IExecutionContext, IDisposable, IAsyncDisposable  | 
16 | 16 |     {  | 
17 | 17 |         internal const string EvaluationScriptUrl = "__puppeteer_evaluation_script__";  | 
18 | 18 |         private const string EvaluationScriptSuffix = $"//# sourceURL={EvaluationScriptUrl}";  | 
19 | 19 | 
 
  | 
20 |  | -        private static readonly Regex _sourceUrlRegex = new(@"^[\040\t]*\/\/[@#] sourceURL=\s*\S*?\s*$", RegexOptions.Multiline);  | 
 | 20 | +#if NETSTANDARD2_0  | 
 | 21 | +        private static readonly Regex _sourceUrlRegex =  | 
 | 22 | +            new(@"^[\040\t]*\/\/[@#] sourceURL=\s*\S*?\s*$", RegexOptions.Multiline);  | 
 | 23 | +#endif  | 
 | 24 | + | 
21 | 25 |         private readonly TaskQueue _puppeteerUtilQueue = new();  | 
22 | 26 |         private IJSHandle _puppeteerUtil;  | 
23 | 27 | 
 
  | 
@@ -128,6 +132,13 @@ internal IJSHandle CreateJSHandle(RemoteObject remoteObject)  | 
128 | 132 |                 ? new CdpElementHandle(World, remoteObject)  | 
129 | 133 |                 : new CdpJSHandle(World, remoteObject);  | 
130 | 134 | 
 
  | 
 | 135 | +#if NET8_0_OR_GREATER  | 
 | 136 | +        [GeneratedRegex(@"^[\040\t]*\/\/[@#] sourceURL=\s*\S*?\s*$", RegexOptions.Multiline)]  | 
 | 137 | +        private static partial Regex GetSourceUrlRegex();  | 
 | 138 | +#else  | 
 | 139 | +        private static Regex GetSourceUrlRegex() => _sourceUrlRegex;  | 
 | 140 | +#endif  | 
 | 141 | + | 
131 | 142 |         private static string GetExceptionMessage(EvaluateExceptionResponseDetails exceptionDetails)  | 
132 | 143 |         {  | 
133 | 144 |             if (exceptionDetails.Exception != null)  | 
@@ -179,7 +190,7 @@ private async Task<T> RemoteObjectTaskToObject<T>(Task<RemoteObject> remote)  | 
179 | 190 |         private Task<RemoteObject> EvaluateExpressionInternalAsync(bool returnByValue, string script)  | 
180 | 191 |             => ExecuteEvaluationAsync("Runtime.evaluate", new Dictionary<string, object>  | 
181 | 192 |             {  | 
182 |  | -                ["expression"] = _sourceUrlRegex.IsMatch(script) ? script : $"{script}\n{EvaluationScriptSuffix}",  | 
 | 193 | +                ["expression"] = GetSourceUrlRegex().IsMatch(script) ? script : $"{script}\n{EvaluationScriptSuffix}",  | 
183 | 194 |                 ["contextId"] = ContextId,  | 
184 | 195 |                 ["returnByValue"] = returnByValue,  | 
185 | 196 |                 ["awaitPromise"] = true,  | 
 | 
0 commit comments