Chrome Extension edit source file - google-chrome

I have a chrome extension that is installed via "Load unpacked extension," and I am trying to get it to delete itself or at least change its source code when a function is called. I have the chrome.management.uninstallSelf down, but I also need the source files for it to become changed/gone. Basically, I need the chrome extension to open the local file where its source is located and then delete/change some of the files inside it. Is there any way to do this?

Basically, I need the chrome extension to open the local file where its source is located and then delete/change some of the files inside it. Is there any way to do this?
No, this isn't normally* possible.
Chrome extensions have only read-only access to their own files (via chrome.runtime.getPackageDirectoryEntry or requests to chrome-extension://), and no access at all to the rest of the filesystem.
* All bets are off if you have a Native Host module though. It can do whatever, but would greatly complicate installation.

Related

Chrome Dev Tools - Workspace mapping mismatch

I have a remote webpage that loads a remote JavaScript file called script.js. I don't have immediate access to the remote filesystem to make changes to test something.
So I copy script.js to my local drive, and in Chrome Dev Tools I add my local folder to the workspace. Then I right-click on my remote script.js file and pick Map to File System Resource.... I pick my local script.js.
So now I would expect my locale changes to script.js to override the remote script.js, right? This way I can make some changes to my local script.js and when I reload the page I can see the changes being reflected on my page.
However in the Sources tab, when selecting my local script.js I see the warning at the top:
Workspace mapping mismatch
The content of this file on the file system:
file:///Users/me/test/script.js
does not match the loaded script:
http://someserver.com/js/script.js
Possible solutions are:
- Reload inspected page
- Check that your file and script are both loaded from the correct source and their contents match
So is this telling me that my local script.js needs to be exactly the same as the remote script.js? If so, then what is the point of the local resource?
Isn't it there so that you can make changes to it and see those changes reflected in the browser? If it has to match the remote file, then you must already have access to be able to edit the remote file, in which case you would be making your changes there and not on the local file. If that is the case, then what is the point of having the local resource mapped?
Am I missing something here? Is it not possible to make temporary local changes to a file in Chrome Dev Tools and have those changes be reflected when the page is reloaded? I thought that was the purpose of the Local File System Resources.
Workspaces is built to map the same file that's in file and served over the network. (like serving ~/code/app to localhost:8000).
It will not work for serving a local file as a replacement. There are some Chrome extensions for this, I recommend Flip the Script.

How to allow download of files on a HTML server?

I have setup a HTML Server to run on Windows Server 2012. I have added few virtual directories and some files.
I am trying to download a file firmware.dob. But when I click on the file the browser reports "File not found"
404 - File or directory not found.
As an admin, how do i enable users/make the browser to download file rather that try to open it?
This should be done by PHP. If you have just HTML i don't think this can be solved. In PHP you could set a Header. Perhaps you can use your admin tools of your server to set some properties of the file you're talking about. maybe the server gives you the option to force download prompts.
If you can only use HTML you might consider using a flash plugin for this. But this would only work on desktops, not on mobile phones. You could look into this: Creating download prompt using purely javascript

How to load local resource in Chrome App

In my Chrome App,I want to load local resources such as audio from user's disk.
If I add the absolute path in my code, the Chrome says "not allowed to load local resource"...
So,how to achive it? Thx
Please this is app not extension.
Chrome Apps are not allowed to access the user's file system directly. file:// URLs are forbidden, as are all the other ways you might try for accessing a file like /home/user/music/demo.mp3. This is by design (so users can install a random Chrome App and trust that it isn't going to read or write their files).
However, Chrome Apps have several APIs available for accessing sandboxed file systems. Since your example is an MP3 file in /home/user/music, you probably should use chrome.mediaGalleries, which will prompt the user for access to common media directories (like /home/user/music) at install time. Then you will be able to access certain file types in certain directories, and prompt the user for music and images in other directories.
As sowbug suggested, you could also use chrome.fileSystem, where you can prompt the user to open a file or directory of their choosing. This will give you access to all files in those directories, but you should only use this if you want non-media file types.

open shared folder from web application

I have one in house Perl web application (Windows OS), and I need to find the best way to open shared folder from my application with user default file explorer. I prefer some Perl module or some cross browser method (I don't know what browser would be used by user).
I tried with file:/// but I am searching for something better.
If what you are trying to achieve is something like accessing a file on a samba share, I would suggest simply using UNC paths (\yourserver\shared_folder\filename). If you point to an actual file it will be opened by the default program associated with that extension in Windows. If you point to a folder, the windows explorer would open up in that folder, as if you typed the UNC path in a start -> run dialog box.
So in perl this would be like below, if your shared folder is on server named "phobos" with a share "movies".
system('\\phobos\movies'); # mind the quoting!!
If you were trying to open up a file in the default program in windows you would use something like:
system('\\phobos\movies\my_cool_movie.avi'); # mind the quoting!!
Is that what you mean with your question?

HTML 5 GeoLocation in Google Chrome

I am using HTML 5 Geolocations API's for tracking location however I am getting the following error on the Geolocation icon in Chrome Browser
"This Page has been blocked from tracking your Location"
I went to the Preferences and Setting's Page but did not find any help.
In my case the problem was that I opened the HTML file from the file system (file:///...). Browsers generally try to prevent accessing personal information (which includes location) from local files, so you have to serve the file through a web server (even if it is local).
One simple way to serve a static website located in your filesystem is SimpleHTTPServer if you have Python installed. Just navigate to the folder using the command prompt, and say python -m SimpleHTTPServer, and then you can view the file on localhost:8000.
Even I was facing the same problem. One of the solution is to open to file in another browser, I tried in Firefox and it worked fine. Another solution is to open the file through your WAMP server (Local host).
There is a good article here about Geolocation API. You have to go to chrome://settings/content and there, you can find Location information. You should be able to find the exceptions and manage them there.