feat: add playwright.utils.injectJQuery#1337
Merged
B4nan merged 4 commits intoapify:masterfrom Apr 28, 2022
barjin:feat/plwtJquery
Merged
feat: add playwright.utils.injectJQuery#1337B4nan merged 4 commits intoapify:masterfrom barjin:feat/plwtJquery
playwright.utils.injectJQuery#1337B4nan merged 4 commits intoapify:masterfrom
barjin:feat/plwtJquery
Conversation
Puppeteer.injectFile survival fixed
Member
Author
|
Swapping |
B4nan
reviewed
Apr 23, 2022
|
tks for the work, will be useful here :) |
mnmkng
requested changes
Apr 24, 2022
| import Request from './request'; // eslint-disable-line no-unused-vars | ||
|
|
||
| const jqueryPath = require.resolve('jquery'); | ||
| const readFilePromised = util.promisify(fs.readFile); |
Member
There was a problem hiding this comment.
There's fs.promises now. no need to promisify anymore
Comment on lines
+59
to
+61
| ? Promise.all([page.on('framenavigated', async () => { | ||
| await page.evaluate(contents); | ||
| }), evalP]) |
Member
There was a problem hiding this comment.
Does Playwright have some special async handling for the page.on listener? If not, this will cause an unhandled rejection if the evaluate throws. Plus AFAIK page.on does not return a promise, so the Promise.all is redundant.
| }; | ||
|
|
||
| /** | ||
| * Injects the [jQuery](https://jquery.com/) library into a Puppeteer page. |
Member
There was a problem hiding this comment.
Suggested change
| * Injects the [jQuery](https://jquery.com/) library into a Puppeteer page. | |
| * Injects the [jQuery](https://jquery.com/) library into a Playwright page. |
| * | ||
| * **Example usage:** | ||
| * ```javascript | ||
| * await Apify.utils.puppeteer.injectJQuery(page); |
Member
There was a problem hiding this comment.
Suggested change
| * await Apify.utils.puppeteer.injectJQuery(page); | |
| * await Apify.utils.playwright.injectJQuery(page); |
B4nan
approved these changes
Apr 28, 2022
playwright.utils.injectJQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #1336
JQuery requires the global
documentobject, which is not available whenPage.addInitScript-s are added. This solution, therefore, introduces the newinjectFileoptionwaitForDOM, which ensures the script does not get injected until the DOM load.The implementation of
waitForDOMneeds rework. Loading bigger scripts (as JQuery, for instance) takes a longer time and introduces "race condition," as there is no way of waiting for the script load to finish. This makes testing + usage a guessing game.