-
Notifications
You must be signed in to change notification settings - Fork 19
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
Allow to transform entries before saving a HAR #174
Labels
Comments
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
You can modify the entries before saving the HAR by using the `transform` option. This option should be set to a path to a module that exports a function, similar to the filter option, to change the Entry object as desired. ```js cy.recordHar({ transform: '../support/remove-sensitive-data.ts' }); ``` Here's a simple example of what the `remove-sensitive-data.ts` module might look like: ```ts import { Entry } from 'har-format'; const PASSWORD_REGEXP = /("password":\s*")\w+("\s*)/; export default async (entry: Entry) => { try { // Remove sensitive information from the request body if (entry.request.postData?.text) { entry.request.postData.text = entry.request.postData.text.replace( PASSWORD_REGEXP, '$1***$2' ); } return entry; } catch { return entry; } }; ``` In this example, the transform function will replace any instances of password with `***` in both the request and response bodies of each entry. closes #174
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
derevnjuk
added a commit
that referenced
this issue
Feb 1, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
It would be useful to have a way to transform recorded entries before saving the HAR file.
Possible solution
Provide the ability to transform entries by introducing the
transform
option as a path to a module that exports a function to modify entries before saving the HAR. The function should take as a parameter and return an Entry object.Here's an example of how to use the filter option:
And here's an example of what the
truncate-response-body.ts
filter module might look like:This example demonstrates how the transform function can be used to truncate the response body of entries.
Relates to #169 (comment)
The text was updated successfully, but these errors were encountered: