bindMethodsToServiceLocator shadows the overridden methods on a class instance with the parent implementations, see:
import { bindMethodsToServiceLocator, ServiceLocator } from './packages/core/src/index.js';
class Parent {
constructor(locator: ServiceLocator) { bindMethodsToServiceLocator(locator, this); }
public act() { console.log('Parent act() called'); }
}
class Child extends Parent {
constructor(locator: ServiceLocator) { super(locator); }
public override act() { console.log('Child act() called'); }
}
const c = new Child(new ServiceLocator());
c.act(); // expected "Child act() called", got "Parent act() called"
In Crawlee, this only runs when a custom service is supplied ⬇️
|
if ( |
|
storageBackend || |
|
eventManager || |
|
logger || |
|
(configuration !== undefined && configuration !== serviceLocator.getConfiguration()) |
|
) { |
|
const scopedServiceLocator = new ServiceLocator(configuration, eventManager, storageBackend, logger); |
|
serviceLocatorScope = bindMethodsToServiceLocator(scopedServiceLocator, this); |
|
} |
In this case, this breaks crawler instances (e.g. messing with the HTTP navigation in HttpCrawler etc.).
bindMethodsToServiceLocatorshadows the overridden methods on a class instance with the parent implementations, see:In Crawlee, this only runs when a custom service is supplied ⬇️
crawlee/packages/basic-crawler/src/internals/basic-crawler.ts
Lines 832 to 840 in fb75701
In this case, this breaks crawler instances (e.g. messing with the HTTP navigation in
HttpCrawleretc.).