I am setting up an extension that prefills a Google form and adds the current URL into one of the fields in the form. However, the issue is that the extension isn't able to detect the complete URL. It only detects www.xyz.com/home.html while the complete URL includes a location hash(www.xyz.com/home.html#e12345678) which is very important and will need to be added to the form. Any ideas on how I can set this up?
I use the following code:
var url = tabs[0].url;
var furl = "https://docs.google.com/forms/xyz/viewform?entry.123="+url;
window.open(furl);
Related
I am trying to grab the uuid that is assigned to each extenstion/add-on installation. This is not the extension ID that is that same across all extension installations. This is the one that is unique for each user per install.
you can call browser.runtime.getURL('/'); this will return you a url string like moz-extension://9a08sd798-af1b-4572-95ab-9d6866517ade/ then you can parse the string from that or if you need it to open a tab to your popup just put the url to your popup.
let url = browser.runtime.getURL('/dist/frontend/index.html');
browser.tabs.create({
url
})
I am fetching data from an api and it contains image urls. When i try to display the images it is not showing any picture. when i logged using console.log(service.coverImage), i was able to display the image urls. for example
https://s3.eu-west-2.amazonaws.com/ererf3wery/Hillside Plaza Hotel 5cdebeaf34157a0026526f0d/providerImage/hph.jpeg
You notice the link breaks and it doesn't go to the image directly, now i cannot change this in the database. How can i solve this in Nodejs to replace the places so that it becomes complete.
I have used methods like replace and encodeURIComponent but not helping
thank you in advance
The image url looks fine, if you are not able to see the image in web page, try to remove protocol from it.
url = url.replace("https:", "");
If that doesn't work, then try removing spaces as you wanted:
let url = "https://s3.eu-west-2.amazonaws.com/ererf3wery/Hillside Plaza Hotel-5cdebeaf34157a0026526f0d/providerImage/hph.jpeg";
url = url.replace(/\ /g, "%20");
console.log(url)
I have the following code snippet:
WebClient client = new WebClient();
String htmlCode = client.DownloadString(newurl);
webBrowser1.DocumentText = htmlCode;
BTW, webBrowser1 is defined globally elsewhere in the program. Likewise, "newurl" is a valid url also defined globally elsewhere.
WebClient gets the complete html which I pass to webbrowser1 using DocumentText.
This result is all kinds of link, syntax, remote javascript, and other errors as though the html is corrupted. However, if I use
webbrowser1.Navigate(newurl);
the target page displays just fine.
I am getting the source html so I can make changes before I display it.
Clearly I am missing something.
Any thoughts?
Regards,
Jim
webBrowser1.DocumentText = htmlCode; will set the HTML only, but will not load any linked-in resources, such as JS, images, CSS, ... .
If you want to do, what you seem to want to do, you can e.g. load the HTML via a WebClient, rewrite it (this includes changing relative paths to absolute ones or setting a base url), write it to a file, then webbrowser1.Navigate("file://path/to/file");
With this code I create a page in a Google site:
pageEntry = new WebPageEntry();
pageEntry.setTitle(new PlainTextConstruct(PageTitle));
..
..
client.insert(new URL(getContentFeedUrl()), pageEntry);
If the PageTitle contains something like "création" the page will created with the name https://sites.google.com/.../.../cration. So "création" is changed to "cration".
Is the process to change the page name available in the API? I would like to fetch the page by its path, but the only key I have is "création".
Maybe a better solution would be to strip the diacritics from the characters in the string before setting it as a page title? For instance, see the javascript function here. Then you page would be created with the URL /creation, which could be more desireable.
I've got some images in my chrome extension that I want the user to be able to inject into their page when they are using the extension.
The images will show up in the extension pop-up window, but when the user clicks the button to inject them into the page, the page can't access them/see them for some reason. I know there are specific ways of injecting JS and CSS into the page (already doing that) but I don't see any way to do the same thing with images.
I've got the following permissions set in my manifest (added the chrome-extensions:// one hoping that would do it):
"permissions" : [ "tabs", "http://*/*", "https://*/*", "chrome-extension://*/*" ]
Specifically, I'm trying to change the favicon, kind of like this (I've also tried without the leading /, and with chrome.extension.getURL("favicons/example.png")):
iconURL = "/favicons/example.png";
var link = document.createElement("link");
link.type = "image/x-icon";
link.rel = "shortcut icon";
link.href = iconURL;
this.removeLinkIfExists();
this.docHead.appendChild(link);
This code works perfectly if the iconURL is a fully qualified http:// address...
You can see the actual code at my github repo here (favicon.js line 54, called by tabdisplay.js line 260).
In case people are having this problem on Chrome 17 or later, it's because the manifest must include the web_accessible_resources section to allow an image packed within the extension to be injected into a web page.
web accessible resources
Instead of:
iconURL = "/favicons/example.png";
It should be:
iconURL = chrome.extension.getURL("/favicons/example.png");
which returns absolute URL to a file inside extension folder.
Also remove chrome-extension://*/* from manifest as it doesn't do anything.
You can use from CSS as well, make sure to add this image into manifest as well.
"web_accessible_resources": [
inside CSS:
background-image: url("chrome-extension://__MSG_##extension_id__/image.png");
Since you are trying to add an image from the extension into a web page, there are security measures that do not allow directly using a chrome:// url to load things like images.
A solution I can think of is to encode the image into a data uri and sending it as text then using that as the src of the img.
iconURL = "/favicons/example.png";
var link = document.createElement("link");
link.type = "image/x-icon";
link.rel = "shortcut icon";
//convert iconURL into data uri (data:image/png;base64,...)
link.href = iconURL;
this.removeLinkIfExists();
this.docHead.appendChild(link);
However, the only way I can think of to do that conversion is using a canvas element.
The STEEL answer is Ok but limited, if you want to introduce an image in the document, not as background of a div, you can do as follow.
<img id="divId" src="chrome-extension://__MSG_##some_Chrome_Extension_Id/path/image.png">
in the manifest file you does need include.
"web_accessible_resources": ["image.png","anotherImage.png"]