I have a PDF storred in a Blob
var pdfBlob = new Blob(buffers, {type: 'application/pdf'});
From that I create an Object URL
var pdfURL = URL.createObjectURL(pdfBlob);
That gives something like blob:chrome-extension%3A//mlbdgii.
If I manually copy the URL to a Chrome tab the PDF is successfully opened. However if I try to open it using chrome.app.window.create I just get a "This webpage is not found" error.
So the question is, can I open an Object URL using this method? If not, is there a workaround to get a PDF stored in an ObjectURL to be displayed in a Chrome App or Chrome Tab ?
Check out this: https://stackoverflow.com/a/27256841/3826713 , I had a similar issue and webview was my workaround for it.
Related
I am getting dynamic link in notification and I want to open dynamic link on notification click.
I am using url_launcher for this purpose but it takes me first to default browser and process the link there and take me back to app.
Is it possible we can process the link inside the app only. I have tried Webview but webview is not opening with dynamic link.
As far as I understand you want to read data from uri link which is generated by firebase in that situation, below code should work :
PendingDynamicLinkData? data =
await FirebaseDynamicLinks.instance.getDynamicLink("Your url here");
String? strLinkData = data.link.toString();
Once you get strLinkData you can move further and do your action.
you can send link like below image
right now i am trying to add a feature where the user can download the files uploaded by them through the URL,
I have tried this code sample:
html.AnchorElement anchorElement = new html.AnchorElement(href: "https://www.example.com/file/path/");
anchorElement.download = "https://www.example.com/file/path/";
anchorElement.click();
But it simply opens the file on the browser, which is not what i want, anyone got any other suggestions?
To summarize the problem, I have several PDF files on my computer that contain links to other pages. Those links, however, direct you to the local filesystem instead of the internet (i.e. clicking the link opens the browser and takes you to file:///page instead of http://domain/page).
Getting these files modified to include the full URL is not an option. My question is almost identical to the question I asked a year and a half ago. The difference is that I need to port my existing extension (made with the Firefox SDK) to the new WebExtensions API for Firefox (same as Chrome extensions).
There are methods available for redirection, such as
browser.webRequest.onBeforeRequest.addListener(
redirect,
{urls:[pattern]},
["blocking"]
);
but that only accepts http:// and https:// URL patterns.
I am currently trying to use the following code:
var id;
browser.tabs.onCreated.addListener( details => id = details.id )
browser.tabs.onUpdated.addListener( (tabId, changeInfo, tab) => {
var url = changeInfo.url;
if (tabId == id && url.includes("file:///")) {
url = url.replace("file:///page", http://domain/page");
browser.tabs.update(
id,
{ url: url }
);
}
});
Unfortunately, I have the same fundamental issue as with my original problem, resulting in the onUpdated listener not firing (or if it does fire, it's not because of a URL change). But regardless of the listener used (e.g. onCreated, onActivated, etc.), I get about:blank for the URL.
I have tried injecting code to change the value of the address bar, but that doesn't seem to work either:
browser.tabs.executeScript( {
code: "window.location.href = window.location.href.replace('file:///', 'http://domain/')"
});
Thanks for any help!
redirectUrl : chrome.extension.getURL("hello.html")
Worked for me
I have a need to point my image tags at a directory that is not part of my app.
The use-case is that this is a kiosk app for which the assets are delivered via Dropbox. So, the user will need to configure the app by pointing the fileSystem object at the required Dropbox directory and then the app will use that directory to source its media.
The fileSystem Entry returns a path that looks like:
~/Dropbox/and/so/on/and/so/forth
I'm trying to figure out if there's any way to use that either explicitly
a la
<img src="~/Dropbox/and/so/on/and/so/fort/image.png"/>
or via some hacky alternative like
<img src="file:///users/someuser/Dropbox/and/so/on/and/so/forth"/>
However all the various combinations I've tried produce a broken image - even though when I inspect the element and click on it in the console Chrome is able to view the image as a stand-alone entity, so I know the path is correct.
I feel like I'm overlooking something obvious, but can't find any documentation for how to correctly aim my resources at the file system.
You'd expect that the fileEntry.toURL() method returns the filesystem:..-URL that can be used to directly embed the image in the page. However, that is not the case because of http://crbug.com/148788.
If you're certain that you can always access the filesystem after requesting permissions, the most efficient solution to embed an image from the user's filesystem is to use blob:-URLs. Here is an example without any error handling:
// Within your app's code, somehow get a DirectoryEntry (or FileEntry):
chrome.fileSystem.chooseEntry({
type: 'openDirectory'
}, function(directoryEntry) {
// Assume that the user has selected the directory containing the images.
directoryEntry.getFile('path/to/img.png', function(fileEntry) {
fileEntry.file(function(file) {
var url = URL.createObjectURL(file);
// url looks like "blob:chrome-extension%3A//[extensionid]/[uuid]"
var img = new Image();
img.src = url;
document.body.appendChild(img);
});
});
});
If you don't know the image path in advance, then you could either enumerate the items in the directory using a DirectoryReader (created using directoryEntry.createReader()), or directly prompt for the FileEntry (and use fileEntry.file, etc., to get the blob:-URL).
To try out the previous snippet, use the following as manifest.json
{
"name": "FS App",
"version": "2",
"manifest_version": 2,
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": [
{"fileSystem": ["directory"]}
]
}
background.js
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('main.html');
});
main.html
<script src="main.js"></script> <!-- main.js = previous code -->
Create a directory that contains "path/to/img.png", load the app, launch the app and click on the just-created directory that contains that picture. You will see that the image is embedded in the app's document.
You don't use a file:// URL, nor do you use any --allow... exceptions. Once you have a FileEntry, you fetch the binary data from the image and form it into a data URL, which you can use directly as an img src. See my answer to this question: chrome packaged app image access
UPDATE: Given a File object (file), here's the code to set the src property of an image (img):
img.src = webkitURL.createObjectURL(file);
If you have a FileEntry, you can get its File via the file() method.
Are the assets in the user's Dropbox or yours? If they are yours, you should be able to get them using fetch after making them public.
I am using the grails facebook-sdk plugin to connect and post to facebook.
To publish a message to a user's wall I use:
def publishMessageResponse = facebookClient.publish("me/feed", [message:"RestFB test"])
This works fine, but I want to post an image to a specific album of the user. The documentation says that it should work with:
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test cat"], "/cat.png")
But I alway get a "File not found" error. The image I have is stored in a data base and can be retrieved by getting the url to the image.
Knowing the url of the image, how can I post this image to a specific user photo album? How can I create a new Album?
I haven't used the facebook-sdk but I would assume that the issue is that it can't find the file '/cat.png' relative to the location of you're project. You'll need to provide valid and accessible file path.
You could confirm this by doing something like this before publishFile...
assert new File("/cat.png").exists(), "File does not exist!"
UPDATE:
Here is an example of converting a url to a file. This may not be the ideal solution if there are other options besides using an actual file.
def someUrl = "http://www.google.com/images/logo.gif";
def file = File.createTempFile("facebookUpload",".temp").withOutputStream { out ->
out << new URL(someUrl).openStream()
}
file.deleteOnExit();
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test cat"], file)