-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow to reuse a browser by passing a browserContext
#884
base: master
Are you sure you want to change the base?
Conversation
browserContext
browserContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no suggestions.
…arity and maintainability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (3)
src/scrapers/base-scraper-with-browser.ts:85
- [nitpick] The word 'bang' might be confusing. It would be clearer to use 'exclamation mark (!)' instead.
NOTICE - it is discouraged to use bang (!) in general.
src/scrapers/base-isracard-amex.ts:33
- The ExtendedScraperOptions interface was removed, but there was no mention of its removal in the context provided. Ensure that this interface is not used elsewhere in the codebase.
type CompanyServiceOptions = {
src/scrapers/base-isracard-amex.ts:258
- [nitpick] The parameter name 'options' is of type 'CompanyServiceOptions'. It would be clearer to rename it to 'companyServiceOptions'.
async function getExtraScrapTransaction(page: Page, options:CompanyServiceOptions, month: Moment, accountIndex: number, transaction: Transaction): Promise<Transaction> {
@@ -26,49 +26,40 @@ export interface FutureDebit { | |||
bankAccountNumber?: string; | |||
} | |||
|
|||
export interface ScraperOptions { | |||
interface ExternalBrowserOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain how one ScraperOptions
interface became to be a union of three interfaces with another fourth interface.
Sorry, something is not clear here, as you can see.
Maybe it is naming only, but it is not clear to me what is the difference between ExternalBrowserOptions
and ExternalBrowserContextOptions
, do are they both new ways to reuse a browser?
And if they are, why is there a third interface DefaultBrowserOptions
? I guess this is the regular way of launching a new browser for each scraper.
Now after your change it is clear there are two different things inside one interface: Browser Settings and Scraping Settings. Maybe we need to split the interfaces or at least insert one of the subjects inside a property (scrapeConfig: ScrapeConfig
) in the other one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain how one ScraperOptions interface became to be a union of three interfaces with another fourth interface.
...
Maybe it is naming only, but it is not clear to me what is the difference between ExternalBrowserOptions and ExternalBrowserContextOptions, do are they both new ways to reuse a browser?
The code had two ways to create a page:
- The default way - the scraper creates the browser, the caller can supply some options for the creation.
- Named
DefaultBrowserOptions
in this PR
- Named
- The non-default way - the caller supplies an external single use browser (because
browser.close()
is called)- Named
ExternalBrowserOptions
in this PR
- Named
In this PR i added the third way, where the caller only supplies a BrowserContext and is responsible for the browser creation and teardown (named ExternalBrowserContextOptions
)
Now after your change it is clear there are two different things inside one interface: Browser Settings and Scraping Settings. Maybe we need to split the interfaces or at least insert one of the subjects inside a property (scrapeConfig: ScrapeConfig) in the other one.
In order to stay backwards compatible, I didn't want to add a new browserOptions
property to ScraperOptions
, therefore left it as export type ScraperOptions = ScraperBrowserOptions & { ... /* All non-browser options */ }
This pull request changes the page creation logic by alowing a
browserContext
to be passes instead of abrowser
(that is currently being closed when the scraping ends)