Skip to content

Commit 4f344a4

Browse files
authored
Cache isolated handle (#2613)
1 parent 2e6a2c0 commit 4f344a4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/PuppeteerSharp/ElementHandle.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace PuppeteerSharp
1717
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1818
public abstract class ElementHandle : JSHandle, IElementHandle
1919
{
20+
private ElementHandle _isolatedHandle;
21+
2022
internal ElementHandle(
2123
IsolatedWorld world,
2224
RemoteObject remoteObject) : base(world, remoteObject)
@@ -722,7 +724,17 @@ protected async Task<TResult> BindIsolatedHandleAsync<TResult, TElementHandle>(F
722724
return await action((TElementHandle)this).ConfigureAwait(false);
723725
}
724726

725-
var adoptedThis = await Frame.IsolatedRealm.AdoptHandleAsync(this).ConfigureAwait(false) as ElementHandle;
727+
ElementHandle adoptedThis;
728+
729+
if (_isolatedHandle == null)
730+
{
731+
_isolatedHandle = adoptedThis = await Frame.IsolatedRealm.AdoptHandleAsync(this).ConfigureAwait(false) as ElementHandle;
732+
}
733+
else
734+
{
735+
adoptedThis = _isolatedHandle;
736+
}
737+
726738
var result = await action((TElementHandle)adoptedThis).ConfigureAwait(false);
727739

728740
if (result is IJSHandle jsHandleResult)

0 commit comments

Comments
 (0)