-
Notifications
You must be signed in to change notification settings - Fork 50
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: Add options to ignore specific urls and regex patterns #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ export default class Logger { | |
private xhrIdMap: { [key: number]: number } = {}; | ||
private maxRequests: number = 500; | ||
private ignoredHosts: Set<string> | undefined; | ||
private ignoredUrls: Set<string> | undefined; | ||
private ignoredPatterns: RegExp[] | undefined; | ||
public enabled = false; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
|
@@ -52,6 +54,18 @@ export default class Logger { | |
} | ||
} | ||
|
||
if (this.ignoredUrls && this.ignoredUrls.has(url)) { | ||
return; | ||
} | ||
|
||
if (this.ignoredPatterns) { | ||
if ( | ||
this.ignoredPatterns.some((pattern) => pattern.test(`${method} ${url}`)) | ||
) { | ||
return; | ||
} | ||
} | ||
|
||
const newRequest = new NetworkRequestInfo( | ||
`${nextXHRId}`, | ||
'XMLHttpRequest', | ||
|
@@ -152,6 +166,23 @@ export default class Logger { | |
this.ignoredHosts = new Set(options.ignoredHosts); | ||
} | ||
|
||
if (options?.ignoredPatterns) { | ||
this.ignoredPatterns = options.ignoredPatterns; | ||
} | ||
|
||
if (options?.ignoredUrls) { | ||
if ( | ||
!Array.isArray(options.ignoredUrls) || | ||
typeof options.ignoredUrls[0] !== 'string' | ||
) { | ||
warn( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this may be better as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I can't remember why I did the warning as it was a while ago when I set it up. I would probably accept a PR updating it. |
||
'ignoredUrls must be an array of strings. The logger has not been started.' | ||
); | ||
return; | ||
} | ||
this.ignoredUrls = new Set(options.ignoredUrls); | ||
} | ||
|
||
XHRInterceptor.setOpenCallback(this.openCallback); | ||
XHRInterceptor.setRequestHeaderCallback(this.requestHeadersCallback); | ||
XHRInterceptor.setHeaderReceivedCallback(this.headerReceivedCallback); | ||
|
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.
Would shrink the code down
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.
The code above where it gets used actually relies on it being undefined. I might just leave it to keep it consistent with the
ignoredHosts
option.