You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: add clone command
* feat: adding more generic rerouteLocal function to handle both document and asset type files
* chore: update readme
* chore: add changest
Copy file name to clipboardExpand all lines: README.md
+40-1Lines changed: 40 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,9 +92,48 @@ You can then reuse the session by using the `login` option when using the `run`
92
92
npx @heymp/scratchpad@next run --login
93
93
```
94
94
95
+
#### Reroute Local Files
96
+
97
+
The `rerouteLocal` function allows you to replace the contents of a document or asset file with a local file from your system. This is incredibly useful for testing changes or developing components in the context of a live site without deploying your code.
98
+
99
+
When used, `rerouteLocal` also watches for file for changes. If you save an update to the file, the Playwright page will automatically reload to reflect your latest edits, providing a fast feedback loop.
100
+
101
+
**How it works:**
102
+
103
+
* It intercepts requests made by the Playwright `page.
104
+
* If the request is not of type `document` it will URL's path to a local file structure.
105
+
* If the request is of type `document` (e.g. `http://example.com/user/profile`) and you've set your local directory to `'./my-pages'`, the function will look for `'./my-pages/user/profile/index.html'`.
106
+
107
+
**Usage:**
108
+
109
+
You would typically use this function within the `playwright` async method in your `scratchpad.config.js`:
url:'https://example.com', // The initial URL you are working with
117
+
playwright:async (args) => {
118
+
const { page } = args;
119
+
120
+
// Tell Scratchpad to serve local HTML files from the './pages' directory
121
+
// whenever a document is requested.
122
+
awaitrerouteLocal(page, './pages');
123
+
124
+
// Now, if you navigate to https://example.com/some/path,
125
+
// Scratchpad will try to serve './pages/some/path/index.html'.
126
+
// If that file doesn't exist, it will load the original page from the web.
127
+
128
+
// If there is a local file of `./assets/scripts.js` it will serve the contents
129
+
// of that local file.
130
+
}
131
+
});
132
+
```
133
+
95
134
🚨 It is highly recommended to add the `.scratchpad` directory to your .gitignore file. Never commit or share your session `login.json` file!
96
135
97
-
#### Reroute Documents
136
+
#### Reroute Documents[deprecated]
98
137
99
138
The `rerouteDocument` function allows you to replace the HTML content of any webpage with a local HTML file from your system. This is incredibly useful for testing changes or developing components in the context of a live site without deploying your code.
0 commit comments