Chrome extension- Inject script on multiple pages - javascript

I am a newbie to extensions. i want to create a extension, when clicked on the icon it should open up the www.gmail.com, input my user name and password and login automatically,click on the first mail. Your help is highly appreciated. I tried many things like chrome inject api but did't work out.

Like said in comments, go have a look to documentation sample codes, it's a good start.
For your extension you should do something like this :
Open a tab with the gmail.com url.
in the callback, inject a content script in the newly created tab
In the content script put the login and the password in page input and then simulate a submit button click.
Try to do this for a first try. When you get it work, You can try to open the latest email received. Look for tabs and runtime message api to send data or event between injected scripts and background script.

Related

How to inject text from browser extension to web page?

I am creating a Firefox extension with React.js and want to inject a text into the active website. The permissions, content_script and background script are set in manifest.json but the problem is I do not understand the concept how it should work.
So far I tried to add content script but that runs a script at page load and thats it. The background does not seem to interact with the page.
I need a script that listen for an event, when I click on a button in the extension popup, it should send the text from the React app to update the site. Basically like a password manager when you injecting the password into the form field.
Can someone tell me the concept as I do not get what case relevant to my problem after checking in and out the web extension documentation?

iOS 12 Shortcut Setup Question for "Run JavaScript on Web Page"

I'm hoping this is the right place for this question since it centers around JavaScript. In the new iOS 12 Shortcuts app you can create workflows. I want to create one that simply launches a web page, fills in my username and password, then clicks the submit button, something like this...
document.myForm.username.value = 'myUsername';
document.myForm.password.value = 'myPassword';
document.getElementById('loginSubmit').submit();
But before even getting that far I just want to run an alert(1);. I can't get that to happen. I keep getting this error message below...
Run JavaScript on Web Page failed because Shortcuts couldn't convert
from URL to Safari web page.
I'm not sure what that means. I haven't been able to find info or tutorials on how to use this. Does anyone know how to get JavaScript to run? Thanks!
the first thing you need to know is that docs are here: https://support.apple.com/guide/shortcuts/welcome/ios
Now, the problem is that "Run Javascript on web page" need an input called "Safari web pages" but Open urls only gives as output the result of opening the url that is showing the page in safari, in order to make it work you need Open url to give you a "Safari web page" item.
The only way that I found to do that is to use the shortcut as a "Share extension"
In your workflow delete the URL item
Go to the shortcut settings page by tapping the icon
Settings icon
Now tap on "Show in Share Sheet"
In the "Accepted types" section, select only URLs that is at the very bottom of the list.
Finally go to safari, open the url you want and tap the share button, if this is the first time you do this, you need to active the "Shortcuts" section, in the bottom list go to the end and tap in "More", the scroll down and select "Shortcuts"
After doing that you will have the Shortcuts option, tap on it and select your Shortcut and it will run the java script in the page.
Is important to note that you will need to do something with the output of "Run javascript on web pages" like showing the result in one alert, because the way you have your workflow now, it may look like nothing is happening.
There's a note in the Run JavaScript on Web Page action that says, "Safari Web Page item in shortcuts stating that they are only available when running your shortcut as an Action Extension in Safari."
So, sadly, it's not possible to chain up actions where it launches a URL and then runs JS. You must visit the url and run the action from the share sheet.
The Safari actions require Safari to be open to the page you want when you launch the activity. That said, you can accomplish this easily using another element.
I don’t know your technical level, so I apologize if any of this is stuff you already know, but for you and for future reference to anyone looking, here is the howto.
First, go to the page you want on a Mac/PC browser and open the developer tools. I use Firefox Developer Edition, but Safari and Chrome have them also. If you’re using MacOS Safari, you will first need to open Safari’s Preferences menu and check “developer options” and relaunch.
Once the developer tools are open, switch to the Network tab / pane; find and turn off the option which clears the log on each page load. Keep this pane open, fill out the form, hit the trash can to clear the network log, and then submit the form. Now the HTTP request of the form submission should be either the first or the only thing in the list.
Select the line for the form submission and look at the request header. There should be a Request Method, Request Url, and all the key-value pairs that were submitted with the form.
Back in the Shortcuts app, add a URL element and give it the same URL as the Request Url. Chain this URL input element to a Get Contents of URL action element and toggle open the Advanced drawer. If there are any additional headers in the request log, you can tap Add new header to add more. Match the Request-Type to the Method field, choose “Form” as the Request Body, and then add in all the keys and values from the request.
Anyways, that’s it.
Chain this to Set Variable then use an IF block to test if the login succeeded or not. If it succeeded, make a Show Result that says “You are now logged in.” and if it failed, show the variable so that you can debug the response.
For API requests in shortcuts, I typically use the Get Contents of URL shortcut, which allows you to use different HTTP methods (POST, GET, etc) and adjust the URL parameters.
In your case, once you authenticate, you could use the authentication token to make other requests as needed.
View Apple's documentation here for an example

Make Google Bot detect AJAX contents

I'm developing a site (not mine) and I encountered a big trouble!
In this website I've got some modals that will open after a user clicks on a product, but I need to do so Google Bot detects these modals like pages. When a modal opens, a JS Function adds a # parameter to the URL like "#abc=modal_one".
I want that in Google Result appears this page as "www.test.com/page.php?#abc=modal_one". I've tried (and I'm trying) to render the page like Google Bot in Google Search Console, but GSC opens only the page and not the modal. I also added a ES6 (JS) code that just edits the page title when the modal is showing to the user (after user clicks to open the modal) but nothing, Google does not detect the page title set after the page is loaded.
If you can't understand something just tell me and I will try to explain my trouble newly.
Thanks in advance to all the StackOverflow community :)
Try exporting the various pages to a dynamic sitemap that Google can read.
View the Categorize parameters with the URL Parameters tool page for more information.

How do I get a marketo form embed to work on my page?

I have a landing page created outside Marketo and I've been asked to embed a form script. It's not showing up.
I tested the lightbox version- this one does work.
I tested other scripts and they don't work.
I tested on a simple html page and it doesn't show up. (I thought maybe because I have other scripts running.)
I do not have access to their Marketo account. Is there something they can do to allow me to embed this on my host server?
Thanks!
Have your client right click the form they want to embed, click 'Embed Code', select the code type as normal, then copy the script Marketo provides.
See these instructions:
http://developers.marketo.com/documentation/websites/forms-2-0/
You can ask the customer to follow these steps to re-generate the HTML embed code and then try to implement it again.
If you're still having troubles please send a link to this page.

Chrome extension - Share data between view and the extension

I'm building a chrome extension to debrid and stream a link on my raspberry pi (running Kodi).
So far, it's working well. I can give a link :
and it's debrided + streamed on Kodi.
I would like to make it easier to use.
Instead of pasting the link into the app, I made a little script to search on a given type of page if a link can be debrided via Realdebrid and is so, the script add a button to directly stream it :
The problem here is :
When the user click on the button, how can I pass the link to my extension ? I would like to have it in my extension because I can display the link into history.
I tried something like that :
from the view :
from the extension :
But it's not working.
I think I should use messages but I don't understand how.
It's an open source project that you can find on Github.
As it's not working yet you won't find the code I shared in the 2 images before. It's just on my computer, not pushed.
Any help would be really appreciated !
Thanks !
EDIT 1 :
When I click on the button injected in the page, I get this error :
Which leads to this line :
EDIT 2 :
If I keep the app open while I click on the button it's working. But I do not want to have to launch the app of course, the goal is to click on the button only.
Popup script is loaded when you open the app by a user action i.e clicking on the app icon. Until then, it is not available to you. As such you are getting this error because when you send a request the listener should be available and in your case its not there.
Now, the easiest way to achieve this would be to send the request from the content script to the background page which is available even when the app is not open.
Inject the button using the content script and send a message to the background page (called event pages) on click event of the button.
Add an event listener in your background page which will listen to the request from the content script and store the link in the local storage.
When your app opens just load the link from the local storage and display your links in the history.
I hope this helps.

Categories

Resources