Chrome extension - using the filesystem API - google-chrome

The filesystem API cannot be used by unpacked extensions, which is awfully great for development.
But then the real surprise came when I realized I can't use it also with my extension packed, because Chrome tells me it cannot find it in the store and is thus greyed out.
Is there any way to actually develop with the filesystem API then?
My goal, in case this is the wrong direction in the first place, is to write some text to a file when some events in the browser happen. The file should be rewritten, rather than creating a new file, which is why I can't use the downloads API.
Is there any way out of this conundrum?

For anyone stumbling on the same issue - a decent solution is to use the chrome.downloads API to download the file in overwrite and incognito mode.
Overwrite will stop the automatic indices added to downloaded file names, and incognito makes the download invisible in the browser except for incognito windows.
The main shortcoming is that it is of course constrained to the user's downloads folder.

Related

Chrome is blocking json downloads - is there a way to prevent this?

Today, Chrome started blocking downloads of json files for us. We use them in our internal content management system for moving files from one environment to another. But it isn't just us. We also use Firebase and can't do an export from there either. I know about the workaround to click Show all and keep the "dangerous file", but how can we prevent Chrome from blocking them in the first place?
There seems to be an issue with Chrome blocking various extensions downloads, hopefully this gets resolved soon.

How to remember last download location when calling chrome.downloads.download? (Extension Developer)

The default behavior for chrome.downloads.download is to download to the default download folder. It doesn't remember it if you change the folder. Can we save the download-to location for the next call-out?
References: https://developer.chrome.com/extensions/downloads
It's concerning that Chrome actually doesn't provide the ability for an extension to get the last download path. Some say, it's due to security concern and others say, there is no significant need to have the API available to users.
You also cannot store the download path in your extension because Chrome doesn't let you get the selected download folder. I hope Google provides us with the either of these features later.
This is not a supported feature, according to this Chromium discussion.
Summary:
If you specify a filename, it's never possible to save outside of ~/Downloads (this is a bummer, for me)
You should be able to manually implement something (in a subfolder only) using the id returned from Chrome.downloads.download
A few quotes I like (edited for brevity and politeness):
Would like a download option to choose recent download folder. Would be good to remember last download location per website, like you other settings.
Seems reasonable.
Chrome does remember the last chosen directory if no filename is specified to downloads.download with Save As... Given how Save As works without specifying a filename, my intuition would be it would work the same with a filename... but it doesn't.
That one is interesting. So it kind of supports it already. There's no security concern with saving outside of Downloads.
I have just been able to restore the "remember last download location" functionality, which used to work on my previous machine, in a new install by disabling extensions and Chrome apps provided by Google. This is what I have turned off:
Extension: Google Docs Offline
Chrome Apps: Docs, Sheets, Slides
I haven't tried to narrow down which of these have been the culprit, or if any other extensions (I have a bunch) have played a role. So YMMV. Good luck :)
SOLVED. Very simple way: Insert a USB-drive or SD-card. Go to chrome settings, and specify this drive as the default download location.
Remove the drive/SD-card. Download something - the first time you do it, Chrome will offer to save to your user document folder, but instead, you save it to whereever you want.
This location will be remembered next time. Voila. So easy.
In fact, you can save previous the download location.
If you do a clean install, first of everything, change the download settings to "ask every time". It is very important not to click the text box where you can specify one download location (if you click there just once, you need a clean install again).
Chrome will then bring up the download window with your last save location.
Furthermore, you should uncheck the "settings" in the sync preferences because it will break every time you sync your settings to a new browser.

Google Chrome --new-window switch ignores --window-position and --window-size

I'm trying to control the size and position of newly spawned Google Chrome windows via the command line (through C#.)
My command line ends up looking like:
--new-window --window-position=100,100 --window-size=800,600 www.UrlToOpen.com
However, the new window just opens over top of where the last Chrome window was started.
The end result I'm looking for is to be able to start multiple instances of Google Chrome, in separate windows, with a specific location and size. The only way I've been able to do this so far is by specifying that each instance is to have it's own --user-data-dir. However, this is not ideal given how many extensions a user may have installed, and it would not be the best user experience.
Does anyone have any suggestions?
If Chrome is not programmed to allow this, you only have one option.
Create the process and keep the process object.
Use Process.MainWindowHandle to get the newly created window (you might need to use a loop and Process.Refresh, or Process.WaitForInputIdle)
Use the SetWindowPos native function to position the window wherever you want it.
Native hooks could be used to detect creation of the window, but that requires you to create an unmanaged DLL.
I have another idea for you, why not use a chrome extension for handling the positioning.
Background: We had related difficulties. Internal webapp that opens multiple documents in windows, and need to be placed in other monitors.
The javascript does not support this, for security reasons and only a native extension can properly work with the tabs/windows objects.
Therefore, we have created an open source chrome extension for doing exactly that: flexible windows position across multi-monitor setups.
Perhaps more interest to you would be the feature to use predefine templates. The template file is located in any webserver you like and therefore can be easily share across different users.
The chrome extension is called "MultiWindow Positioner" and its complete free. You can get it at the chrome store here
The actual source code you find in github in the project chrome-multiwindow-positioner
Disclaimer: I am the maintainer of the open source (MIT) github project. If there any interesting idea, or comments feel free to share them here.

Chrome extension to launch on file open

I'm about to start a Chrome packaged app project which will include a NaCl component to parse CHM files. But before I start, I just want to check if it's possible to get the app to automatically launch when a CHM is opened (when the users clicks on a link to an chm file, or possibly if a chm file is dragged into a Chrome window).
I've come across some Google documentation here which describes associating NaCl modules with MIME types in the extension manifest, but A: I'm not sure if this is relevant to my problem and B: I've tried doing as it describes, but nothing seems to change.
If anyone can point me in the right direction, I'd appreciate it!
I was able to hack around with chrome.webRequest to filter URLs with .chm extensions, but of course that only works when a user clicks on a direct link to a CHM file, and there is no way I know of to access local files outside the sandbox (for good reason no doubt).
I have since decided to make the project a Drive app with the C++ portion squirreled away inside a DLL on an ASP.net server, which makes a lot more sense to me.

How to make Google Chrome recognize this extension as a new extension

I had a chrome extension built for me and it helps me publish to my wordpress with ease. The problem is that I have a few websites that I would like to use the same extension for which involves nothing more than changing the URL in the extension's settings.
The real question
Assuming I made 3 copies of the same extension, what changes must be implemented in each one to make Google Chrome recognize it as a different extension? Right now, if I change certain attributes in the manifest, Chrome will still recognize it as the original extension and will want to replace the extension I already have installed.
I hope this makes sense. Apparently someone didn't understand what I was talking about so I broke it down. Hope someone can help me out.
I'm only guessing, but I would think that it would be the name field found in the manifest.json file. In theory, if you are managing your own .crx file (for packaged extensions), I guess Chrome could use the name of that file as well. And finally, if you are signing your extension and making it available through the market, the cryptographic signature could be used as well (the .pem being created when you package your extension).
So no real answer, but I believe it must be one of these three (name in manifest, name of crx file or cryptographic signature). If you test it and figure out, be sure to share!