question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace `injectFile` to `injectScript` and add `injectCSS`

See original GitHub issue

When browsing trough the docs and using the API, I noticed that Puppeteer has an injectFile method. The name might be confusing, because you might think it works for a CSS file as well. I think it would be better to rename this method to injectScript and also add a injectCSS method.

Just an idea though 😃.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
aslushnikovcommented, Oct 4, 2017

@vsemozhetbyt injectFile injects from file system, whereas addStyleTag adds a url. I’d rather unify the two methods since it’s confusing.

Something like:

page.addScriptTag({
  url: '...', // either URL or PATH could be specified
  path: '..',
});
1reaction
SamVerschuerencommented, Oct 5, 2017

addScriptTag and addStyleTag currently already work with a local file path, that’s what the tests do as well. Not sure if it’s a good idea though, that’s probably the reason why injectFile exists.

If we would go with your solution, an object with url and path, it might be nice to have a content option as well.

page.addScriptTag({
  url: '...',
  path: '..',
  content: `document.write('Hello World')`
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Replace injectFile to injectScript and add injectCSS #949
CSS injecting seems to be possible when #947 is landed. All reactions.
Read more >
Inject CSS stylesheet as string using Javascript
There are a couple of ways this could be done, but the simplest approach is to create a <style> element, set its textContent...
Read more >
How To Inject CSS Code Into an HTML Page?
gulp-inject is a plugin to inject stylesheets and javascript references into the HTML file. This will allow us to add a placeholder in...
Read more >
puppeteer 0.12.0 on Node.js Yarn
#892 - Add addStyleTag(url) API; #949 - Replace injectFile to injectScript and add injectCSS; #1010 - ElementHandle screenshot does not count padding (or ......
Read more >
Create a Chrome Extension to Inject Script | by Piyush Dubey
A guide to creating a chrome extension to inject any script into the client application. Create a Chrome Extension to Inject script.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found