Chrome complains of MIME type wrong - browser

I have created a simple PHP script which downloads files (sends them to the browser). The script sends the browser the type of document, for example MIME type "application/gz" for example document test.tar.gz
However, on receiving the document Chrome complains:
Resource interpreted as Document but transferred with MIME type application/gz
Am I setting the wrong MIME type? (Please don't focus on why I'm creating my own download script...just the MIME issue)

VCSjones was correct - I needed to change the MIME type to application/gzip and then Chrome no longer complained.

Related

Not able to access storage in Content Scripts in Chrome Extension Manifest V3

I tried to access information stored in chrome.storage.session in my content script, but the browser keeps informing me that "Access to storage is not allowed from this context" even though I enabled "storage" in manifest.json
After fetching some data in my background script, I store the received
chrome.storage.session.set({"data": data});
However, when I try to access it in my content script by running the following line:
chrome.storage.session.get(["data"],function(data){console.log(data)})
I got the following error:
Uncaught TypeError: Cannot read properties of undefined (reading 'session')
However, when I run the exact same command in my background script, I was able to retrieve the data.
I also made sure I enabled "storage" permission in my manifest.json. Why is this happening?
Thanks so much in advance!
Access to storage is not allowed from this context
As the documentation says session is only for trusted contexts by default.
To enable it in the content scripts call setAccessLevel from such a trusted context i.e. in the background script or in an extension page like the action popup or options.
chrome.storage.session.setAccessLevel({ accessLevel: 'TRUSTED_AND_UNTRUSTED_CONTEXTS' });
Cannot read properties of undefined (reading 'session')
This error says that the parent of session is undefined i.e. chrome.storage is undefined, which can only happen in these cases:
you didn't reload the extension after editing manifest.json
an orphaned content script tried to access storage after you reloaded or updated the extension
your code is not a content script, but just a page script e.g. you ran it in a script element or injected with world: 'MAIN'.

Specifying path/filename in downloads.download() api not working in Chrome but does in Firefox

Specifying path/filename to downloading file does not work in chrome.downloads api but does work for firefox browser.downloads api.
I have a very simple call in popup.js for chrome and firefox:
chrome.downloads.download({url: address, filename: path + "/" + filename, saveAs: false});
Here's another one for Firefox:
browser.downloads.download({url: addresss, filename: path + "/" + filename, saveAs: false});
It works perfectly as expected in firefox, but no matter what, I can't ever get it to work in chrome. Even with a simple download of google's image to a different file name never works chrome but does in firefox, such as:
chrome.downloads.download({url: "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", filname: "temp/temp.png"});
What am I doing wrong?
It's been awhile but I'll post my solution for whoever comes across this issue for their extension. It turns out that specifying a custom filename isn't working is because there are extension conflicts.
If there is another extension using the chrome.downloads API, specifically the chrome.downloads.onDeterminingFilename.addListener, which tries to specify the filename that overrides the original filename suggestion. This also happens even if the conflicting extension did not change your download options but just added a listener for onDeterminingFilename without doing any logic. This is a known chromium issue here: https://bugs.chromium.org/p/chromium/issues/detail?id=579563. That issue has been opened since 2016 and the devs still have not addressed it.
Workaround solution: implement your own chrome.downloads.onDeterminingFilename.addListener to suggest your custom filename. Make sure that you're only capturing downloads that you started yourself but comparing the download item's id and extension id. The only caveat is that the conflicting extension will produce an error saying they could not suggest their own filename.
Firefox does not have this issue because their extension API does not have onDeterminingFilename.

why chrome.runtime undefined by http but work fine by https

When i debug javaScript on devtool.
chrome.runtime
see "http://www.qq.com",it show:
chrome.runtime is undefined. see http preview.
But when i debug it on https site (https://www.qq.com ).it work fine. see https preview.
tips: all script run on top frame.
Can i change "chorme:flags" to enable it ?
i got why now.
"chrome.runtime.sendMessage" not exist when no extension installed.---since chrome 66+.
see:https://bugs.chromium.org/p/chromium/issues/detail?id=835287
Comment 29 by rdevlin....#chromium.org, Apr 25 For at least some of
these cases from the duped bugs, I think this was caused by revision
39f8939309fe39bccc17fa1280b6c7f25c411947. This modified the
externally_connectable property of the cryptotoken component extension
(automatically built into Chrome) to only accept incoming connections
from https URLs, whereas previously it was all URLs. When it was set
to all URLs, chrome.runtime.sendMessage would always be available
because any URL could potentially send a message to the cryptotoken
component extension.
However, this is working as intended. The cryptotoken extension only
accepts connections from https origins (so any others would be
ignored), and sending a message to any other extension would require
the receiving extension to list the URL in the externally_connectable
options. Additionally, this means that before, any extension relying
on this behavior would likely have failed to send the message, but
done so asynchronously (once the message failed to find an appropriate
receiver) rather than synchronously (since runtime is undefined). If
the extension lists the URL in externally_connectable, then
chrome.runtime should still be present. If the extension does not
list the site in externally_connectable, then chrome.runtime not being
available is intended behavior.
Is there any case in which chrome.runtime is undefined for
non-sandboxed chrome-extension:// pages, or for web pages where an
installed extension specifies that web page's URL in the
externally_connectable field of the manifest? If so, please attach an
extension that demonstrates this issue. If not, this sounds like it's
WAI.
fix: add one extionsion with:manifest.
"externally_connectable": {
"ids": [
"*"
],
"matches": [
"http://test.yoursite.in:9090/*",
"*://*.chromium.org/*"
]
},
thinks all.

Servicestack return wrong content type when returning a file with html extension

I am testing Servicestack Rest Files service. When calling it from angularjs and asking for an html file back, the results comes back as the standard servicestack html format instead of the json format. Even when appending ?format=json, it does not work correctly. I am trying to browse for html files and are then trying to load it into ace editor. I think Servicestack is getting confused with the response type. I checked and the Content-Type is set to application/json on the client side when doing the request.
I'm assuming the request you're making is:
GET /files/myfile.html
It's returing HTML because the .html file extension is a built-in registered format in ServiceStack so it assumes you're explicitly requesting the API in the HTML Format.
You can avoid this ambiguity by specifying the file Path on the QueryString, e.g:
GET /files?Path=myfile.html
Which tells ServiceStack to send it back using the most appropriate format as specified in the Accept header. Or if you prefer you can also explicitly specify the format by adding the {.ext} at the end of the path info, e.g:
GET /files.json?Path=myfile.html
Another option, if you're not using ServiceStack's built-in HTML support is to remove the HtmlFormat Plugin, e.g:
Plugins.RemoveAll(x => x is HtmlFormat);
Whicih will make .html no longer a registered format so the .html extension will be benign.
Note: removing HtmlFormat also removes built-in HTML functionality like its auto HTML pages

File not supported error while uploading profile image file to IBM Connections using REST API

I'm trying to upload a jpeg file for profile image using the Profiles REST API to IBM Connections_v5.0. I however get an error message "The type of the photo file you provided is not supported".
I'm however able to upload the same file directly using the Connections UI interface directly. I'm setting the MIME type correctly as "image/jpeg".
Also tried with GIF and PNG images but get the same error message.
Any pointers would be very helpful.
I'm just using FF restclient addon to fire a REST call. So basically doing a PUT on /profiles/photo.do?key=....
Content-Type is set as "image/jpeg" and the payload consists of the image data in binary (base 64) encoded.
The payload should just be the binary of the image, there is no need to Base64 encode it.
You should refer to Adding a Profile Photo
You need to use a Key (great stackoverflow post here)
If you know the key for a user's profile you can do the following:
key — This is generated by Connections itself during the population
process. It is used to define the users profile within the context of
Profiles and provides Connections with the ability to associate
content with a user when the users LDAP information has been altered.
It provides a separation of identity and helps facilitate user content
synchronization for Connections.
Once you have a key, you make the following request
URL: https://profiles.enterprise.example.com/profiles/photo.do?key=
b559403a-9r32-2c81-c99w-ppq8bb69442
METHOD: PUT
CONTENT-TYPE: image/png
input the binary content on the stream
you should be able to use "image/jpeg", "image/jpg", "image/png" or "image/gif"
If you have an error after the PUT method, you should add the SystemOut.log lines which are relevant.

Resources