How to Run Rails App in a Completely Isolated Instances of Chrome

How to run rails app in a completely isolated instances of chrome?

Chrome and Firefox supports using multiple profiles that won't affect each other, reusable (unlike incognito) and can even have entirely different extension ecosystem.

By creating and using multiple profiles, you can do development — creating extensions, modifying the browser, or testing the browser — while still being able to use Google Chrome as your default browser.

How to do it:

From Chromium docs:

The details of how to create and use a profile vary by platform, but here's the basic process:

  • Create a folder to hold data for the new profile.
  • Create a shortcut or alias that launches the browser, using the --user-data-dir command-line argument to specify the profile's location.
  • Whenever you launch the browser, use the shortcut or alias that's associated with the profile. If the profile folder is empty, the browser creates initial data for it.

In other words, simply create an empty directory somewhere and run this to open a new instance of chrome that's completely separate from any current one:

open -n -a "Google Chrome" --args --user-data-dir=$(mktemp -d)

Related:

  • see here for how to open chrome on mac and pass it arguments
  • see here for how to create a random temp directory in bash
  • see here for more on 'How do I start Chrome using a specified “user profile”?'

Headless Chrome with Rspec database connection not working

When you're running feature tests, it's recommended to use :truncation clean method. Just add something like this to your database_cleaner config:

config.before(:each, type: :feature) do
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test

DatabaseCleaner.strategy = :truncation if !driver_shares_db_connection_with_specs
end

Source: https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example

Finding/killing a memory problem in a specific controller in rails

The standout issue is this:

Notifier.new_comment(@comment).deliver if Rails.env == 'production' unless @comment.marked_as_spam

I'm assuming this is an ActionMailer object. deliver is a blocking method and not something you'd usually want to use in production during the request-response cycle. This could cause major delays if your mail server is slow to respond, so you should replace it with deliver_later and ensure you have a tool like Sidekiq available to fulfill the request in the background.

(deliver is deprecated as of Rails 5 btw, in favour of deliver_now and deliver_later.)

CAUTION: provisional headers are shown in Chrome debugger

The resource could be being blocked by an extension (AdBlock in my case).

The message is there because the request to retrieve that resource was never made, so the headers being shown are not the real thing. As explained in the issue you referenced, the real headers are updated when the server responds, but there is no response if the request was blocked.


The way I found about the extension that was blocking my resource was through the net-internals tool in Chrome:

For Latest Versions of chrome

  • Type chrome://net-export/ in the address bar and hit enter.
  • Start Recording. And save Recording file to local.
  • Open the page that is showing problems.
  • Go back to net-internals
  • You can view Recorded Log file Here https://netlog-viewer.appspot.com/#import
  • click on events (###) and use the textfield to find the event related to your resource (use parts of the URL).
  • Finally, click on the event and see if the info shown tells you something.

For Older Versions of chrome

  • Type chrome://net-internals in the address bar and hit enter.
  • Open the page that is showing problems.
  • Go back to net-internals, click on events (###) and use the textfield to find the event related to your resource (use parts of the URL).
  • Finally, click on the event and see if the info shown tells you something.


Related Topics



Leave a reply



Submit