How to pack a Chrome extension on Mac OSX with commandline? - macos

I am trying to automate my Chrome extension building process on OSX 10.5.
I am unable to find a similar command for OSX like this for Windows
chrome.exe --pack-extension=c:\myext
--pack-extension-key=c:\myext.pem
Is it even possible on OSX? As there is no mention of it in the documentation.
Please guide me.
Thanks in advance.
-Parimal Das

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --pack-extension...

Use the CRXMake gem.
Have a great day.

A complete example to run on the shell:
"/Users/varr/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --pack-extension="/Users/varr/Dropbox/Code/Projects/Bookmark Express/src"
Things to note:
Chrome will not display any output of success or failure but it will return an exit code
Your shell (ex. oh-my-zsh) may display exit codes so you can have an idea there
Chrome will generate two files, the .crx and a .pem
To automate this, I used Geb (and Groovy). In GebConfig.groovy, I tried using:
def chromePath = "/Users/varr/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
def packExtensionSwitch='--pack-extension="/Users/varr/Dropbox/Code/Projects/Bookmark Express/src"'
ProcessBuilder packExtension = new ProcessBuilder(chromePath, packExtensionSwitch)
Process process = packExtension.start()
But this returned an exit code 21 every time and no files were generated. I finalized my approach with:
def packageExtensionScript = '/Users/varr/package.sh'
ProcessBuilder packExtension = new ProcessBuilder(packageExtensionScript)
Process process = packExtension.start()
To finish it up, I made package.sh a one-line script with the command to run and it all worked!

You can use A node.js command line app for packing Google Chrome extensions too. Enjoy!

Related

How to close tab with selenium on macos with chrome driver?

My code
from selenium import webdriver
dr = webdriver.Chrome()
dr.close()
I got this error
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
The error is telling you what is wrong: the chromedriver program is not found in your executable path (stored in the environment as $PATH).
You can tell what the current path is using something like this:
import os
print os.environ['PATH']
Once you know the path, you can install chromedriver into one of the directories in the path.
The correct solution would be to just add the path of your chrome driver. The best way to do that is just have the chrome driver in the same directory as you are probably going to be updating it a lot since google is still working on it.

Headless in Windows 7 for Ruby in Watir?

I am new here. Is there any way to use headless in windows? I tried but it says :
:/Ruby193/lib/ruby/gems/1.9.1/gems/headless-1.0.1/lib/headless/cli_util.rb:4:in ``': No such file or directory - which Xvfb (Errno::ENOENT)
Please help...
Headless Tests in "WINDOWS7" using WATIR? You can use phantomjs which is super easy to configure.
Follow these easy steps:
Download phantomjs from here
Extract to desired folder, once extracted you just need phantomjs.exe
Now where ever you instantiating the browser, use it like this:
phantom_dir = "location of phantomjs.exe"
ENV['PATH'] = "#{ENV['PATH']}#{File::PATH_SEPARATOR}#{ghost_dir}"
browser = Watir::Browser.new :"phantomjs"
To run headless on other OS follow easy steps here
You have to run it on a linux box. Xvfb doesn't exist in Windows or Mac

Installing CasperJS on Windows: How to do it correctly?

I know there is a documentation from CasperJS website about how to install CasperJS on Windows, but bear with me these guys only explained for the pros only.
If you are new to all this CasperJS and PhantomJS world, you dont stand a chance to understand not even spending two days trying to search the net for a better explanation.
I am working on a project that requires a screenshot of each website listed on my project website, looking around i found out that PhantomJS would be great for this task (website screenshot).
I downloaded PhantomJS and and pasted its phantomjs.exe file in system32 which is working well when i use cmd.exe to send command.
I even managed to grab screenshot with the phantomjs.exe only. but my problem came when i noticed the the workload could be easier when these two work together (CasperJS and PhantomJS) as i can even be able to reduce the size of the screenshot when using CasperJS.
In fact the only use that i want CasperJS for is the limiting of the shot size but since yesterday i have been trying to figure out how to make CasperJS work on Windows but with no avail.
I have downloaded CasperJS and tried to install it in many ways also trying to follow the documentation but nothing.
I changed the CasperJS folder name from its download name to CasperJS as the documantation suggest but when i check in the cmd trying to call some commands, nothing happens.
Anyway to cut the story shot can anyone help me in simple terms considering that i am a newbie to explain how CasperJS can be installed on window or if possible with PhantomJS only how can i re-size the iamge the the program produces lets say if i want a 960 to 400px.
Poor documentation for windows. http://casperjs.org/installation.html#windows
It starts off assuming you have already installed without telling you how to install.
So here it is if anyone else is confused about this. There is no actual install. It's just extracting zip contents to the right place.
download phantomjs for windows from the phantomjs site (it's a zip with binary inside)
extract the contents to C:\phantomjs
download the casperjs zip file from the casperjs website
extract the contents to C:\casperjs
Now you can add the following to the end your system or user PATH variable
;C:\phantomjs;C:\casperjs\batchbin
restart cmd.exe to pick up the new path variable or logout/login if you are running Console2 or Conemu terminal emulator (they won't pick up new paths by a simple close and re-open)
Now in the docs it says to run it like this
casperjs.bat myscript.js
Actually since both phantomjs.exe and casperjs.bat are now in the system PATH you can leave off the extension like this.
casperjs myscript.js
And when running phantomjs.exe just run
phantomjs
One more thing. It really doesn't matter where you install as long as you add that path to the system PATH. I installed to C:\usr\phantomjs and C:\usr\casperjs.
I itemize below the method that has served my needs on both my personal Windows and Ubuntu work PC. DO note that my method doesn't fiddle with PATH settings but involves a command you could save somewhere & copy and paste as needed:
Step 1: Gather the prerequisites
Download the casperjs and phantomjs versions you want to use
Make a directory to contain the things I want to list
Extract the downloaded phantomjs & copy its executable into the directory of step b
Extract casperjs and rename its folder to casperjs
Copy the renamed casperjs folder to the directory of step b
Create and save a file config.json to the directory of step b
config.json should contain phantomjs configurations as found here: http://phantomjs.org/api/command-line.html
Step 2: Running your script
Whenever you want to work with a file, follow the Step 1 details above
The next step assumes that you are in the directory created in step
b of Step 1 also have a file named first.js
On Windows: phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli first.js
On Ubuntu: ./phantomjs --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli first.js
Experimental config.js and first.js are listed below:
config.json
{"sslProtocol": "any", "cookiesFile": "biscuit", "maxDiskCacheSize": 1000, "diskCache": true}
first.js
var casper = require('casper').create({
pageSettings: {
loadImages: false,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
}
});
var url = "http://casperjs.org/";
casper.start(url).wait(60 * 1000 * 1, function() {
casper.echo('1 min has passed');
casper.capture('casperjs.png');
casper.exit();
});
casper.run();
Addendum: download and save the details of screenshots.js and run it as
phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli screenshots.js http://phantomjs.org
Run Tests: download & save the details of picturefill-test.js and run it as
phantomjs.exe --config=config.json casperjs/bin/bootstrap.js
--casper-path=casperjs test --cli picturefill-test.js
As of CasperJS 1.1.0-DEV Beta 3 you should use this PATH: C:\casperjs\batchbin even though the documentation found here states you need to use C:\casperjs\bin
The reason to this is because C:\casperjs\batchbin includes a .BAT which C:\casperjs\bin does not include anything except some.js files.
after a 3days work, i managed to get it work the problem was with the path and the installation of phantom. i had made the path to a folder but the installation was pointing to the exe file all i had to do was to put the exe file into a folder phantomjs and that was it thank for your help all.
Many of the other answers are out of date. Since it seems like the correct install process keeps changing all the time, I suspect my answer will be out of date also in a few days, but as of March 19, 2015, this is the answer. The other answers, even highly upvoted ones, do not work, so don't waste your time. Good luck. Casperjs seems quite good.
If you download PhantomJS 2.0 and casperjs 1.1-beta3 zip file and put the batchbin directory in the path and put phantom exe in that same folder, then run casperjs, on Windows 8.1 I get the error "CasperJS needs PhantomJS v1.x".
So, I got the latest casperjs direct from github, which has no batchbin directory, so I put just the C:\casperjs\bin directory in the path instead and this worked (sort of, I mean it seems to work well enough for me - although running casperjs c:\casperjs\tests\selftest.js seems to have a number of failing tests).
So to recap, the bad news is only the very latest bleeding edge casperjs works. The good news is the install is 1,2,3 simple:
Clone latest casperjs from github into c:\casperjs.
Copy phantomjs.exe (ver 2.0) to c:\casperjs\bin
Add c:\casperjs\bin to your windows path
Just in case you're using a notebook with dual graphic cards like I do: choose one of them to prevent issues. This article helped me out:
casperJS not finishing on windows
the casperJS documentation is pretty clear about it but I had no clue what to do until I read the notice above.
Fast forward to 2015... 5-steps win7 howto:
choco: PS me> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
git: choco install git -y
phantomjs 2.0: choco install phantomjs -y
casperjs source: git clone https://github.com/n1k0/casperjs -b phantomjs-2
Add the location of casperjs/bin to PATH
Done. You can now casperjs --version and live happily ever after.
Ok guys. So I think this thread needs refreshing for 2018!
So with npm, the effort is reduced significantly. Given that you have npm installed, open terminal and go to your project:
cd your_project_name
Now install casperjs. Use --save-dev, --save, -g or none as needed:
npm install --save-dev casperjs
Now install phantomjs. To do this, you should install phantomjs-prebuilt, because PhantomJS team changed their package name:
npm install --save-dev phantomjs-prebuilt
Run your spec:
casperjs your_spec_name.js

Fabfile path problem on windows

I'm trying to deploy my site using Fabric and Mercurial. In the Windows command line, running hg push works perfectly with no problems.
But when I try writing
local("hg push")
in a fabfile and running it, I get the error:
'"hg push"' is not recognized as an internal or external command, operable program or batch file.
Googling gave me an idea that it might be a problem with the PATH variable in Python subprocesses, for example here: Why would an "command not recognized" error occur only when a window is populated?.
Can you help me out? Is the bug in Fabric or in my own code?
Thanks.
As Chris R mentions, we don't do a ton of Windows support as none of the core devs are Windows users; we have to rely on reports and suggestions from our more savvy Windows users.
It sounds like this could be related to this recently fixed, but not released, bug -- it will be in Fabric 1.0.2 which should be out soon. If you're feeling brave, you can test it out now via:
pip install -e git+git://github.com/bitprophet/fabric#1.0#egg=Fabric
If you then do fab -V, it should say it's 1.0.2a -- if so, running your fabfile may work better. Please let us know if you do this!
It sounds like the you need to add Mercurial to the Fabric process's PATH.
Maybe something like:
fabric.context_managers.path(<path to your hg.exe>)
run('hg push')
See the docs for the path context manager. It wasn't clear if path applies to local commands, but run commands are explicitly referenced.
Neither of the fixes provided worked, but changing
local("hg push")
to
os.system("hg push")
solved the problem.

Open local HTML file in default web browser

IS there any way in Ruby to open a local HTML file in the user's default web browser? I could do something like:
system("open /path/to/file.html")
But that would only work on Mac OS X. Are there any solutions that work on any platform?
You can use the launchy gem.
First, install the gem:
$ [sudo] gem install launchy
Then, in your ruby code:
require 'rubygems'
require 'launchy'
Launchy::Browser.run("/path/to/file.html")
I think you will have to do system specific calls.
system() is like writing the command on the local system command line (that's my understanding anywayz)
I can't do what you have done on Windows 7. I have to call explorer and it opens in my default browser.
Windows 7 Example: (opens in Chrome, my default browser)
system("explorer file:///C:/path_to_file")
Note: I needed to put file:/// at the start otherwise it opens in Explorer instead of the browser.
I know it's not desirable, however worst case, you can check the value of RUBY_PLATFORM. This returns the operating system platform.
Semi-Pseudo Code:
cmd = case RUBY_PLATFORM
when /darwin/
"open /path/to/file.html"
when /windows/ #fix this, I'm not sure.
"explorer file:///C:/path_to_file"
else
"default"
end
system(cmd)

Resources