Best JavaScript code snippet using playwright-internal
ReactFiberUnwindWork.js
Source:ReactFiberUnwindWork.js
1/**2 * Copyright (c) Facebook, Inc. and its affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @flow8 */9import type {Fiber} from './ReactFiber';10import type {FiberRoot} from './ReactFiberRoot';11import type {ExpirationTime} from './ReactFiberExpirationTime';12import type {CapturedValue} from './ReactCapturedValue';13import type {Update} from './ReactUpdateQueue';14import type {Thenable} from './ReactFiberScheduler';15import type {SuspenseState} from './ReactFiberSuspenseComponent';16import {unstable_wrap as Schedule_tracing_wrap} from 'scheduler/tracing';17import getComponentName from 'shared/getComponentName';18import warningWithoutStack from 'shared/warningWithoutStack';19import {20 ClassComponent,21 HostRoot,22 HostComponent,23 HostPortal,24 ContextProvider,25 SuspenseComponent,26 DehydratedSuspenseComponent,27 IncompleteClassComponent,28} from 'shared/ReactWorkTags';29import {30 DidCapture,31 Incomplete,32 NoEffect,33 ShouldCapture,34 LifecycleEffectMask,35} from 'shared/ReactSideEffectTags';36import {37 enableSchedulerTracing,38 enableSuspenseServerRenderer,39} from 'shared/ReactFeatureFlags';40import {ConcurrentMode} from './ReactTypeOfMode';41import {shouldCaptureSuspense} from './ReactFiberSuspenseComponent';42import {createCapturedValue} from './ReactCapturedValue';43import {44 enqueueCapturedUpdate,45 createUpdate,46 CaptureUpdate,47 ForceUpdate,48 enqueueUpdate,49} from './ReactUpdateQueue';50import {logError} from './ReactFiberCommitWork';51import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';52import {popHostContainer, popHostContext} from './ReactFiberHostContext';53import {54 isContextProvider as isLegacyContextProvider,55 popContext as popLegacyContext,56 popTopLevelContextObject as popTopLevelLegacyContextObject,57} from './ReactFiberContext';58import {popProvider} from './ReactFiberNewContext';59import {60 renderDidSuspend,61 renderDidError,62 onUncaughtError,63 markLegacyErrorBoundaryAsFailed,64 isAlreadyFailedLegacyErrorBoundary,65 pingSuspendedRoot,66 retryTimedOutBoundary,67} from './ReactFiberScheduler';68import invariant from 'shared/invariant';69import maxSigned31BitInt from './maxSigned31BitInt';70import {71 Sync,72 expirationTimeToMs,73 LOW_PRIORITY_EXPIRATION,74} from './ReactFiberExpirationTime';75import {findEarliestOutstandingPriorityLevel} from './ReactFiberPendingPriority';76const PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;77const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;78function createRootErrorUpdate(79 fiber: Fiber,80 errorInfo: CapturedValue<mixed>,81 expirationTime: ExpirationTime,82): Update<mixed> {83 const update = createUpdate(expirationTime);84 // Unmount the root by rendering null.85 update.tag = CaptureUpdate;86 // Caution: React DevTools currently depends on this property87 // being called "element".88 update.payload = {element: null};89 const error = errorInfo.value;90 update.callback = () => {91 onUncaughtError(error);92 logError(fiber, errorInfo);93 };94 return update;95}96function createClassErrorUpdate(97 fiber: Fiber,98 errorInfo: CapturedValue<mixed>,99 expirationTime: ExpirationTime,100): Update<mixed> {101 const update = createUpdate(expirationTime);102 update.tag = CaptureUpdate;103 const getDerivedStateFromError = fiber.type.getDerivedStateFromError;104 if (typeof getDerivedStateFromError === 'function') {105 const error = errorInfo.value;106 update.payload = () => {107 return getDerivedStateFromError(error);108 };109 }110 const inst = fiber.stateNode;111 if (inst !== null && typeof inst.componentDidCatch === 'function') {112 update.callback = function callback() {113 if (typeof getDerivedStateFromError !== 'function') {114 // To preserve the preexisting retry behavior of error boundaries,115 // we keep track of which ones already failed during this batch.116 // This gets reset before we yield back to the browser.117 // TODO: Warn in strict mode if getDerivedStateFromError is118 // not defined.119 markLegacyErrorBoundaryAsFailed(this);120 }121 const error = errorInfo.value;122 const stack = errorInfo.stack;123 logError(fiber, errorInfo);124 this.componentDidCatch(error, {125 componentStack: stack !== null ? stack : '',126 });127 if (__DEV__) {128 if (typeof getDerivedStateFromError !== 'function') {129 // If componentDidCatch is the only error boundary method defined,130 // then it needs to call setState to recover from errors.131 // If no state update is scheduled then the boundary will swallow the error.132 warningWithoutStack(133 fiber.expirationTime === Sync,134 '%s: Error boundaries should implement getDerivedStateFromError(). ' +135 'In that method, return a state update to display an error message or fallback UI.',136 getComponentName(fiber.type) || 'Unknown',137 );138 }139 }140 };141 }142 return update;143}144function attachPingListener(145 root: FiberRoot,146 renderExpirationTime: ExpirationTime,147 thenable: Thenable,148) {149 // Attach a listener to the promise to "ping" the root and retry. But150 // only if one does not already exist for the current render expiration151 // time (which acts like a "thread ID" here).152 let pingCache = root.pingCache;153 let threadIDs;154 if (pingCache === null) {155 pingCache = root.pingCache = new PossiblyWeakMap();156 threadIDs = new Set();157 pingCache.set(thenable, threadIDs);158 } else {159 threadIDs = pingCache.get(thenable);160 if (threadIDs === undefined) {161 threadIDs = new Set();162 pingCache.set(thenable, threadIDs);163 }164 }165 if (!threadIDs.has(renderExpirationTime)) {166 // Memoize using the thread ID to prevent redundant listeners.167 threadIDs.add(renderExpirationTime);168 let ping = pingSuspendedRoot.bind(169 null,170 root,171 thenable,172 renderExpirationTime,173 );174 if (enableSchedulerTracing) {175 ping = Schedule_tracing_wrap(ping);176 }177 thenable.then(ping, ping);178 }179}180function throwException(181 root: FiberRoot,182 returnFiber: Fiber,183 sourceFiber: Fiber,184 value: mixed,185 renderExpirationTime: ExpirationTime,186) {187 // The source fiber did not complete.188 sourceFiber.effectTag |= Incomplete;189 // Its effect list is no longer valid.190 sourceFiber.firstEffect = sourceFiber.lastEffect = null;191 if (192 value !== null &&193 typeof value === 'object' &&194 typeof value.then === 'function'195 ) {196 // This is a thenable.197 const thenable: Thenable = (value: any);198 // Find the earliest timeout threshold of all the placeholders in the199 // ancestor path. We could avoid this traversal by storing the thresholds on200 // the stack, but we choose not to because we only hit this path if we're201 // IO-bound (i.e. if something suspends). Whereas the stack is used even in202 // the non-IO- bound case.203 let workInProgress = returnFiber;204 let earliestTimeoutMs = -1;205 let startTimeMs = -1;206 do {207 if (workInProgress.tag === SuspenseComponent) {208 const current = workInProgress.alternate;209 if (current !== null) {210 const currentState: SuspenseState | null = current.memoizedState;211 if (currentState !== null) {212 // Reached a boundary that already timed out. Do not search213 // any further.214 const timedOutAt = currentState.timedOutAt;215 startTimeMs = expirationTimeToMs(timedOutAt);216 // Do not search any further.217 break;218 }219 }220 let timeoutPropMs = workInProgress.pendingProps.maxDuration;221 if (typeof timeoutPropMs === 'number') {222 if (timeoutPropMs <= 0) {223 earliestTimeoutMs = 0;224 } else if (225 earliestTimeoutMs === -1 ||226 timeoutPropMs < earliestTimeoutMs227 ) {228 earliestTimeoutMs = timeoutPropMs;229 }230 }231 }232 // If there is a DehydratedSuspenseComponent we don't have to do anything because233 // if something suspends inside it, we will simply leave that as dehydrated. It234 // will never timeout.235 workInProgress = workInProgress.return;236 } while (workInProgress !== null);237 // Schedule the nearest Suspense to re-render the timed out view.238 workInProgress = returnFiber;239 do {240 if (241 workInProgress.tag === SuspenseComponent &&242 shouldCaptureSuspense(workInProgress)243 ) {244 // Found the nearest boundary.245 // Stash the promise on the boundary fiber. If the boundary times out, we'll246 // attach another listener to flip the boundary back to its normal state.247 const thenables: Set<Thenable> = (workInProgress.updateQueue: any);248 if (thenables === null) {249 const updateQueue = (new Set(): any);250 updateQueue.add(thenable);251 workInProgress.updateQueue = updateQueue;252 } else {253 thenables.add(thenable);254 }255 // If the boundary is outside of concurrent mode, we should *not*256 // suspend the commit. Pretend as if the suspended component rendered257 // null and keep rendering. In the commit phase, we'll schedule a258 // subsequent synchronous update to re-render the Suspense.259 //260 // Note: It doesn't matter whether the component that suspended was261 // inside a concurrent mode tree. If the Suspense is outside of it, we262 // should *not* suspend the commit.263 if ((workInProgress.mode & ConcurrentMode) === NoEffect) {264 workInProgress.effectTag |= DidCapture;265 // We're going to commit this fiber even though it didn't complete.266 // But we shouldn't call any lifecycle methods or callbacks. Remove267 // all lifecycle effect tags.268 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);269 if (sourceFiber.tag === ClassComponent) {270 const currentSourceFiber = sourceFiber.alternate;271 if (currentSourceFiber === null) {272 // This is a new mount. Change the tag so it's not mistaken for a273 // completed class component. For example, we should not call274 // componentWillUnmount if it is deleted.275 sourceFiber.tag = IncompleteClassComponent;276 } else {277 // When we try rendering again, we should not reuse the current fiber,278 // since it's known to be in an inconsistent state. Use a force updte to279 // prevent a bail out.280 const update = createUpdate(Sync);281 update.tag = ForceUpdate;282 enqueueUpdate(sourceFiber, update);283 }284 }285 // The source fiber did not complete. Mark it with Sync priority to286 // indicate that it still has pending work.287 sourceFiber.expirationTime = Sync;288 // Exit without suspending.289 return;290 }291 // Confirmed that the boundary is in a concurrent mode tree. Continue292 // with the normal suspend path.293 attachPingListener(root, renderExpirationTime, thenable);294 let absoluteTimeoutMs;295 if (earliestTimeoutMs === -1) {296 // If no explicit threshold is given, default to an arbitrarily large297 // value. The actual size doesn't matter because the threshold for the298 // whole tree will be clamped to the expiration time.299 absoluteTimeoutMs = maxSigned31BitInt;300 } else {301 if (startTimeMs === -1) {302 // This suspend happened outside of any already timed-out303 // placeholders. We don't know exactly when the update was304 // scheduled, but we can infer an approximate start time from the305 // expiration time. First, find the earliest uncommitted expiration306 // time in the tree, including work that is suspended. Then subtract307 // the offset used to compute an async update's expiration time.308 // This will cause high priority (interactive) work to expire309 // earlier than necessary, but we can account for this by adjusting310 // for the Just Noticeable Difference.311 const earliestExpirationTime = findEarliestOutstandingPriorityLevel(312 root,313 renderExpirationTime,314 );315 const earliestExpirationTimeMs = expirationTimeToMs(316 earliestExpirationTime,317 );318 startTimeMs = earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;319 }320 absoluteTimeoutMs = startTimeMs + earliestTimeoutMs;321 }322 // Mark the earliest timeout in the suspended fiber's ancestor path.323 // After completing the root, we'll take the largest of all the324 // suspended fiber's timeouts and use it to compute a timeout for the325 // whole tree.326 renderDidSuspend(root, absoluteTimeoutMs, renderExpirationTime);327 workInProgress.effectTag |= ShouldCapture;328 workInProgress.expirationTime = renderExpirationTime;329 return;330 } else if (331 enableSuspenseServerRenderer &&332 workInProgress.tag === DehydratedSuspenseComponent333 ) {334 attachPingListener(root, renderExpirationTime, thenable);335 // Since we already have a current fiber, we can eagerly add a retry listener.336 let retryCache = workInProgress.memoizedState;337 if (retryCache === null) {338 retryCache = workInProgress.memoizedState = new PossiblyWeakSet();339 const current = workInProgress.alternate;340 invariant(341 current,342 'A dehydrated suspense boundary must commit before trying to render. ' +343 'This is probably a bug in React.',344 );345 current.memoizedState = retryCache;346 }347 // Memoize using the boundary fiber to prevent redundant listeners.348 if (!retryCache.has(thenable)) {349 retryCache.add(thenable);350 let retry = retryTimedOutBoundary.bind(351 null,352 workInProgress,353 thenable,354 );355 if (enableSchedulerTracing) {356 retry = Schedule_tracing_wrap(retry);357 }358 thenable.then(retry, retry);359 }360 workInProgress.effectTag |= ShouldCapture;361 workInProgress.expirationTime = renderExpirationTime;362 return;363 }364 // This boundary already captured during this render. Continue to the next365 // boundary.366 workInProgress = workInProgress.return;367 } while (workInProgress !== null);368 // No boundary was found. Fallthrough to error mode.369 // TODO: Use invariant so the message is stripped in prod?370 value = new Error(371 (getComponentName(sourceFiber.type) || 'A React component') +372 ' suspended while rendering, but no fallback UI was specified.\n' +373 '\n' +374 'Add a <Suspense fallback=...> component higher in the tree to ' +375 'provide a loading indicator or placeholder to display.' +376 getStackByFiberInDevAndProd(sourceFiber),377 );378 }379 // We didn't find a boundary that could handle this type of exception. Start380 // over and traverse parent path again, this time treating the exception381 // as an error.382 renderDidError();383 value = createCapturedValue(value, sourceFiber);384 let workInProgress = returnFiber;385 do {386 switch (workInProgress.tag) {387 case HostRoot: {388 const errorInfo = value;389 workInProgress.effectTag |= ShouldCapture;390 workInProgress.expirationTime = renderExpirationTime;391 const update = createRootErrorUpdate(392 workInProgress,393 errorInfo,394 renderExpirationTime,395 );396 enqueueCapturedUpdate(workInProgress, update);397 return;398 }399 case ClassComponent:400 // Capture and retry401 const errorInfo = value;402 const ctor = workInProgress.type;403 const instance = workInProgress.stateNode;404 if (405 (workInProgress.effectTag & DidCapture) === NoEffect &&406 (typeof ctor.getDerivedStateFromError === 'function' ||407 (instance !== null &&408 typeof instance.componentDidCatch === 'function' &&409 !isAlreadyFailedLegacyErrorBoundary(instance)))410 ) {411 workInProgress.effectTag |= ShouldCapture;412 workInProgress.expirationTime = renderExpirationTime;413 // Schedule the error boundary to re-render using updated state414 const update = createClassErrorUpdate(415 workInProgress,416 errorInfo,417 renderExpirationTime,418 );419 enqueueCapturedUpdate(workInProgress, update);420 return;421 }422 break;423 default:424 break;425 }426 workInProgress = workInProgress.return;427 } while (workInProgress !== null);428}429function unwindWork(430 workInProgress: Fiber,431 renderExpirationTime: ExpirationTime,432) {433 switch (workInProgress.tag) {434 case ClassComponent: {435 const Component = workInProgress.type;436 if (isLegacyContextProvider(Component)) {437 popLegacyContext(workInProgress);438 }439 const effectTag = workInProgress.effectTag;440 if (effectTag & ShouldCapture) {441 workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture;442 return workInProgress;443 }444 return null;445 }446 case HostRoot: {447 popHostContainer(workInProgress);448 popTopLevelLegacyContextObject(workInProgress);449 const effectTag = workInProgress.effectTag;450 invariant(451 (effectTag & DidCapture) === NoEffect,452 'The root failed to unmount after an error. This is likely a bug in ' +453 'React. Please file an issue.',454 );455 workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture;456 return workInProgress;457 }458 case HostComponent: {459 // TODO: popHydrationState460 popHostContext(workInProgress);461 return null;462 }463 case SuspenseComponent: {464 const effectTag = workInProgress.effectTag;465 if (effectTag & ShouldCapture) {466 workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture;467 // Captured a suspense effect. Re-render the boundary.468 return workInProgress;469 }470 return null;471 }472 case DehydratedSuspenseComponent: {473 if (enableSuspenseServerRenderer) {474 // TODO: popHydrationState475 const effectTag = workInProgress.effectTag;476 if (effectTag & ShouldCapture) {477 workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture;478 // Captured a suspense effect. Re-render the boundary.479 return workInProgress;480 }481 }482 return null;483 }484 case HostPortal:485 popHostContainer(workInProgress);486 return null;487 case ContextProvider:488 popProvider(workInProgress);489 return null;490 default:491 return null;492 }493}494function unwindInterruptedWork(interruptedWork: Fiber) {495 switch (interruptedWork.tag) {496 case ClassComponent: {497 const childContextTypes = interruptedWork.type.childContextTypes;498 if (childContextTypes !== null && childContextTypes !== undefined) {499 popLegacyContext(interruptedWork);500 }501 break;502 }503 case HostRoot: {504 popHostContainer(interruptedWork);505 popTopLevelLegacyContextObject(interruptedWork);506 break;507 }508 case HostComponent: {509 popHostContext(interruptedWork);510 break;511 }512 case HostPortal:513 popHostContainer(interruptedWork);514 break;515 case ContextProvider:516 popProvider(interruptedWork);517 break;518 default:519 break;520 }521}522export {523 throwException,524 unwindWork,525 unwindInterruptedWork,526 createRootErrorUpdate,527 createClassErrorUpdate,...
FiberWorkLoop.js
Source:FiberWorkLoop.js
...406 }407 const eventTime = requestEventTime();408 ensureRootIsScheduled(root, eventTime);409}410function retryTimedOutBoundary(boundaryFiber, retryLane=NoLane){411 // The boundary fiber (Suspense) previously was rendered in its fallback 412 // state. One of the promises that suspended is has resolved and try 413 // rendering again at a new expiration time.414 if (retryLane === NoLane) {415 retryLane = claimNextRetryLane();416 }417 const eventTime = requestEventTime();418 const root = markUpdateLaneFromChildToRoot(boundaryFiber, retryLane);419 if (root !== null){420 markRootUpdated(root, retryLane, eventTime);421 ensureRootIsScheduled(root, eventTime);422 }423}424export function resolveRetryWakeable(boundaryFiber, wakeable){425 let retryCache = boundaryFiber.stateNode;426 if(retryCache !== null){427 retryCache.delete(wakeable);428 }429 retryTimedOutBoundary(boundaryFiber);...
ReactFiberScheduler.js
Source:ReactFiberScheduler.js
1/**2 * Copyright (c) Facebook, Inc. and its affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @flow8 */9import {enableNewScheduler} from 'shared/ReactFeatureFlags';10import {11 requestCurrentTime as requestCurrentTime_old,12 computeExpirationForFiber as computeExpirationForFiber_old,13 captureCommitPhaseError as captureCommitPhaseError_old,14 onUncaughtError as onUncaughtError_old,15 renderDidSuspend as renderDidSuspend_old,16 renderDidError as renderDidError_old,17 pingSuspendedRoot as pingSuspendedRoot_old,18 retryTimedOutBoundary as retryTimedOutBoundary_old,19 resolveRetryThenable as resolveRetryThenable_old,20 markLegacyErrorBoundaryAsFailed as markLegacyErrorBoundaryAsFailed_old,21 isAlreadyFailedLegacyErrorBoundary as isAlreadyFailedLegacyErrorBoundary_old,22 scheduleWork as scheduleWork_old,23 flushRoot as flushRoot_old,24 batchedUpdates as batchedUpdates_old,25 unbatchedUpdates as unbatchedUpdates_old,26 flushSync as flushSync_old,27 flushControlled as flushControlled_old,28 deferredUpdates as deferredUpdates_old,29 syncUpdates as syncUpdates_old,30 interactiveUpdates as interactiveUpdates_old,31 flushInteractiveUpdates as flushInteractiveUpdates_old,32 computeUniqueAsyncExpiration as computeUniqueAsyncExpiration_old,33 flushPassiveEffects as flushPassiveEffects_old,34 warnIfNotCurrentlyActingUpdatesInDev as warnIfNotCurrentlyActingUpdatesInDev_old,35 inferStartTimeFromExpirationTime as inferStartTimeFromExpirationTime_old,36} from './ReactFiberScheduler.old';37import {38 requestCurrentTime as requestCurrentTime_new,39 computeExpirationForFiber as computeExpirationForFiber_new,40 captureCommitPhaseError as captureCommitPhaseError_new,41 onUncaughtError as onUncaughtError_new,42 renderDidSuspend as renderDidSuspend_new,43 renderDidError as renderDidError_new,44 pingSuspendedRoot as pingSuspendedRoot_new,45 retryTimedOutBoundary as retryTimedOutBoundary_new,46 resolveRetryThenable as resolveRetryThenable_new,47 markLegacyErrorBoundaryAsFailed as markLegacyErrorBoundaryAsFailed_new,48 isAlreadyFailedLegacyErrorBoundary as isAlreadyFailedLegacyErrorBoundary_new,49 scheduleWork as scheduleWork_new,50 flushRoot as flushRoot_new,51 batchedUpdates as batchedUpdates_new,52 unbatchedUpdates as unbatchedUpdates_new,53 flushSync as flushSync_new,54 flushControlled as flushControlled_new,55 deferredUpdates as deferredUpdates_new,56 syncUpdates as syncUpdates_new,57 interactiveUpdates as interactiveUpdates_new,58 flushInteractiveUpdates as flushInteractiveUpdates_new,59 computeUniqueAsyncExpiration as computeUniqueAsyncExpiration_new,60 flushPassiveEffects as flushPassiveEffects_new,61 warnIfNotCurrentlyActingUpdatesInDev as warnIfNotCurrentlyActingUpdatesInDev_new,62 inferStartTimeFromExpirationTime as inferStartTimeFromExpirationTime_new,63} from './ReactFiberScheduler.new';64// enableNewScheduler é½ä¸º falseï¼æ以æ们åªç old ç代ç 65export const requestCurrentTime = enableNewScheduler66 ? requestCurrentTime_new67 : requestCurrentTime_old;68export const computeExpirationForFiber = enableNewScheduler69 ? computeExpirationForFiber_new70 : computeExpirationForFiber_old;71export const captureCommitPhaseError = enableNewScheduler72 ? captureCommitPhaseError_new73 : captureCommitPhaseError_old;74export const onUncaughtError = enableNewScheduler75 ? onUncaughtError_new76 : onUncaughtError_old;77export const renderDidSuspend = enableNewScheduler78 ? renderDidSuspend_new79 : renderDidSuspend_old;80export const renderDidError = enableNewScheduler81 ? renderDidError_new82 : renderDidError_old;83export const pingSuspendedRoot = enableNewScheduler84 ? pingSuspendedRoot_new85 : pingSuspendedRoot_old;86export const retryTimedOutBoundary = enableNewScheduler87 ? retryTimedOutBoundary_new88 : retryTimedOutBoundary_old;89export const resolveRetryThenable = enableNewScheduler90 ? resolveRetryThenable_new91 : resolveRetryThenable_old;92export const markLegacyErrorBoundaryAsFailed = enableNewScheduler93 ? markLegacyErrorBoundaryAsFailed_new94 : markLegacyErrorBoundaryAsFailed_old;95export const isAlreadyFailedLegacyErrorBoundary = enableNewScheduler96 ? isAlreadyFailedLegacyErrorBoundary_new97 : isAlreadyFailedLegacyErrorBoundary_old;98export const scheduleWork = enableNewScheduler99 ? scheduleWork_new100 : scheduleWork_old;101export const flushRoot = enableNewScheduler ? flushRoot_new : flushRoot_old;102export const batchedUpdates = enableNewScheduler103 ? batchedUpdates_new104 : batchedUpdates_old;105export const unbatchedUpdates = enableNewScheduler106 ? unbatchedUpdates_new107 : unbatchedUpdates_old;108export const flushSync = enableNewScheduler ? flushSync_new : flushSync_old;109export const flushControlled = enableNewScheduler110 ? flushControlled_new111 : flushControlled_old;112export const deferredUpdates = enableNewScheduler113 ? deferredUpdates_new114 : deferredUpdates_old;115export const syncUpdates = enableNewScheduler116 ? syncUpdates_new117 : syncUpdates_old;118export const interactiveUpdates = enableNewScheduler119 ? interactiveUpdates_new120 : interactiveUpdates_old;121export const flushInteractiveUpdates = enableNewScheduler122 ? flushInteractiveUpdates_new123 : flushInteractiveUpdates_old;124export const computeUniqueAsyncExpiration = enableNewScheduler125 ? computeUniqueAsyncExpiration_new126 : computeUniqueAsyncExpiration_old;127export const flushPassiveEffects = enableNewScheduler128 ? flushPassiveEffects_new129 : flushPassiveEffects_old;130export const warnIfNotCurrentlyActingUpdatesInDev = enableNewScheduler131 ? warnIfNotCurrentlyActingUpdatesInDev_new132 : warnIfNotCurrentlyActingUpdatesInDev_old;133export const inferStartTimeFromExpirationTime = enableNewScheduler134 ? inferStartTimeFromExpirationTime_new135 : inferStartTimeFromExpirationTime_old;136export type Thenable = {137 then(resolve: () => mixed, reject?: () => mixed): void | Thenable,...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();9 at CDPSession.send (C:\Users\pavani\Documents\Playwright\playwright\lib\client\cdpSession.js:41:19)10 at ExecutionContext._evaluateInternal (C:\Users\pavani\Documents\Playwright\playwright\lib\client\frameManager.js:1061:50)11 at ExecutionContext.evaluateHandle (C:\Users\pavani\Documents\Playwright\playwright\lib\client\frameManager.js:1026:21)12 at Page._retryTimedOutBoundary (C:\Users\pavani\Documents\Playwright\playwright\lib\client\page.js:1615:30)13 at Page.screenshot (C:\Users\pavani\Documents\Playwright\playwright\lib\client\page.js:1468:26)14 at processTicksAndRejections (internal/process/task_queues.js:97:5)15 at async Object.<anonymous> (C:\Users\pavani\Documents\Playwright\test.js:8:3)
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9 at Object.retryTimedOutBoundary (C:\Users\user\playwright\test.js:4:9)10 at async Object.<anonymous> (C:\Users\user\playwright\test.js:11:3)11const { chromium } = require('playwright');12const { retryTimedOutBoundary } = require('playwright/lib/helper');13(async () => {14 const browser = await chromium.launch({ headless: false });15 const context = await browser.newContext();16 const page = await context.newPage();17 await retryTimedOutBoundary(async () => {18 await page.screenshot({ path: `example.png` });19 }, 10000, 'page.screenshot');20 await browser.close();21})();
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('input[name="q"]');7 await page.click('input[name="q"]');8 await page.keyboard.type('Playwright');9 await page.keyboard.press('Enter');10 await page.waitForSelector('text=Results');11 await page.waitForSelector('text=Playwright');12 await page.evaluate(() => {13 window.playwright.internal.retryTimedOutBoundary(() => {14 throw new Error('Test');15 });16 });17 await browser.close();18})();19Your name to display (optional):20Your name to display (optional):21Your name to display (optional):
Using AI Code Generation
1const { chromium } = require('playwright');2const { retryTimedOutBoundary } = require('playwright/lib/utils/timeoutSettings');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await retryTimedOutBoundary(async () => {8 }, page._timeoutSettings.timeout(1000));9 await browser.close();10})();11module.exports = {12 use: {13 viewport: { width: 1280, height: 720 },14 },15};16{17 "scripts": {18 },19 "dependencies": {20 }21}22 at Timeout.setTimeout (/Users/.../node_modules/playwright/lib/utils/timeoutSettings.js:103:19)23 at listOnTimeout (internal/timers.js:549:17)24 at processTimers (internal/timers.js:492:7)25const { chromium } = require('playwright');26const { retryTimedOutBoundary } = require('playwright/lib/utils/timeoutSettings');27(async () => {28 const browser = await chromium.launch();
Using AI Code Generation
1const { chromium } = require('playwright');2const { retryTimedOutBoundary } = require('playwright/lib/server/browserType');3(async () => {4 const browser = await chromium.launch();5 await retryTimedOutBoundary(async () => {6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'google.png' });9 await browser.close();10 });11})();12const { helper } = require('./helper');13const { TimeoutError } = require('../utils/errors');14const { assert } = require('../utils/utils');15const { Browser } = require('./browser');16const { BrowserContext } = require('./browserContext');17const { Events } = require('../events');18const { ConnectionTransport } = require('./transport');19const { WebSocketTransport } = require('./transport');20const { PipeTransport } = require('./transport');21const { ProgressController } = require('./progress');22const { BrowserServer } = require('./browserServer');23const { BrowserFetcher } = require('./browserFetcher');24const { BrowserType } = require('./browserType');25const { devices } = require('../deviceDescriptors');26const { Connection } = require('./connection');27const { BrowserContextChannel } = require('./browserContextChannel');28const { BrowserServerChannel } = require('./browserServerChannel');29const { BrowserTypeChannel } = require('./browserTypeChannel');30const { BrowserChannel } = require('./browserChannel');31const { BrowserContextDispatcher } = require('../dispatchers/browserContextDispatcher');32const { BrowserServerDispatcher } = require('../dispatchers/browserServerDispatcher');33const { BrowserTypeDispatcher } = require('../dispatchers/browserTypeDispatcher');34const { BrowserDispatcher } = require('../dispatchers/browserDispatcher');35const { DispatcherConnection } = require('../dispatchers/dispatcher');36const { BrowserContextOwner } = require('./browserContextOwner');37const { BrowserServerOwner } = require('./browserServerOwner');38const { BrowserTypeOwner } = require('./browserTypeOwner');39const { BrowserOwner } = require('./browserOwner');40module.exports = { helper, TimeoutError, assert, Browser, BrowserContext, Events, ConnectionTransport, WebSocketTransport, PipeTransport, ProgressController, BrowserServer, BrowserFetcher, BrowserType, devices, Connection, Browser
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!