Skip to content

Commit 075af99

Browse files
committed
chore: skip non-configurable properties in ContextPipeline
1 parent f6c13bb commit 075af99

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

packages/core/src/crawlers/context_pipeline.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Awaitable } from '@crawlee/types';
22

3+
import log from '@apify/log';
4+
35
import {
46
ContextPipelineCleanupError,
57
ContextPipelineInitializationError,
@@ -129,7 +131,18 @@ class ContextPipelineImpl<TContextBase, TCrawlingContext extends TContextBase> e
129131
for (const { action, cleanup } of middlewares) {
130132
try {
131133
const contextExtension = await action(crawlingContext);
132-
Object.defineProperties(crawlingContext, Object.getOwnPropertyDescriptors(contextExtension));
134+
135+
const extensionDescriptors = Object.getOwnPropertyDescriptors(contextExtension);
136+
137+
for (const [key, descriptor] of Object.entries(extensionDescriptors)) {
138+
try {
139+
if (Object.getOwnPropertyDescriptor(crawlingContext, key)?.configurable !== false) {
140+
Object.defineProperty(crawlingContext, key, descriptor);
141+
}
142+
} catch (error: any) {
143+
log.debug(`Context pipeline failed to define property ${key}:`, error);
144+
}
145+
}
133146

134147
if (cleanup) {
135148
cleanupStack.push(cleanup);

packages/playwright-crawler/src/internals/adaptive-playwright-crawler.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,20 +521,19 @@ export class AdaptivePlaywrightCrawler<
521521
};
522522

523523
const subCrawlerContext = { ...context };
524+
525+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(resultBoundContextHelpers))) {
526+
Object.defineProperty(subCrawlerContext, key, { ...descriptor, configurable: false });
527+
}
528+
524529
this.resultObjects.set(subCrawlerContext, result);
525530

526531
try {
527532
const callAdaptiveRequestHandler = async () => {
528533
if (renderingType === 'static') {
529-
await this.staticContextPipeline.call(subCrawlerContext, async (finalContext) => {
530-
Object.assign(finalContext, resultBoundContextHelpers);
531-
await this.requestHandler(finalContext);
532-
});
534+
await this.staticContextPipeline.call(subCrawlerContext, this.requestHandler.bind(this));
533535
} else if (renderingType === 'clientOnly') {
534-
await this.browserContextPipeline.call(subCrawlerContext, async (finalContext) => {
535-
Object.assign(finalContext, resultBoundContextHelpers);
536-
await this.requestHandler(finalContext);
537-
});
536+
await this.browserContextPipeline.call(subCrawlerContext, this.requestHandler.bind(this));
538537
}
539538
};
540539

0 commit comments

Comments
 (0)